为了账号安全,请及时绑定邮箱和手机立即绑定

无法将散列数据插入 Wordpress 数据库

无法将散列数据插入 Wordpress 数据库

PHP
呼如林 2022-12-23 16:09:49
我创建了一个函数,该函数使用 生成一个 21 位随机字符串,使用wp_generate_password()对其进行哈希处理wp_hash(),将生成的字符串保存到数据库,然后return将哈希字符串保存到数据库中。它工作得很好。但是,我想做另一种方式,而不是将生成的随机字符串保存到数据库中,我想保存散列字符串和return随机字符串。但它不起作用。当我尝试将散列字符串保存在数据库中时,它根本不会创建任何条目。如果我想保存随机字符串,效果很好。我已经尝试清理散列字符串, applied strval(), applied $wpdb->insertwithformat我将其声明为字符串的地方。什么都不管用!我什至尝试将服务器资源增加到 4GB 内存、2Vcore 处理器。将每个 php.ini 资源限制增加到 3GB。什么都不管用。这是完美运行的功能。但是,在这个函数中,我想用替换'verification_code'=>$email_verification,'verification_code'=>$email_verification_hashed它不起作用。我想让它工作,以便散列字符串进入数据库并返回随机字符串。function generate_verification($user_id) {$user_info = get_userdata($user_id);$email_verification = wp_generate_password( 21, true, true );$email_verification_hashed = wp_hash( $email_verification );if (isset($user_info)) {    global $wpdb;    $table_name = $wpdb->base_prefix.'custom_table'; //already exist            $user_email = $user_info->user_email;       $data = array('email'=>$user_email, 'verification_code'=>$email_verification, 'user_id'=>$user_id);    $where = array('user_id'=>$user_id);    $existing_data = "SELECT * FROM {$wpdb->prefix}custom_table WHERE user_id = {$user_id}";    $existing_data_results = $wpdb->get_results($query);    if($existing_data_results > 0) {        $wpdb->update( $table_name, $data, $where);        return $email_verification_hashed;    } else {        $wpdb->insert( $table_name, $data);        return $email_verification_hashed;    }   } else {    return 'Failed';}}
查看完整描述

1 回答

?
繁星点点滴滴

TA贡献1803条经验 获得超3个赞

这是一个愚蠢的错误,数据库列是VARCHAR(21)哈希字符串比那长得多。我只是将列更改为VARCHAR(255)现在它正在工作



查看完整回答
反对 回复 2022-12-23
  • 1 回答
  • 0 关注
  • 82 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号