Php Can';t将散列数据插入Wordpress数据库
我制作了一个函数,使用Php Can';t将散列数据插入Wordpress数据库,php,mysql,database,wordpress,hash,Php,Mysql,Database,Wordpress,Hash,我制作了一个函数,使用wp\u generate\u password()生成一个21位随机字符串,使用wp\u hash()对其进行散列,将生成的字符串保存到数据库中,并返回散列字符串。它工作得非常好。但是,我想用另一种方法,不是将生成的随机字符串保存到数据库中,而是保存哈希字符串并return随机字符串 但它不起作用。当我试图在数据库中保存哈希字符串时,它根本不会创建任何条目。如果我想保存随机字符串,它的效果非常好 我尝试过清理散列字符串,应用了strval(),应用了$wpdb->inse
wp\u generate\u password()
生成一个21位随机字符串,使用wp\u hash()
对其进行散列,将生成的字符串保存到数据库中,并返回散列字符串。它工作得非常好。但是,我想用另一种方法,不是将生成的随机字符串保存到数据库中,而是保存哈希字符串并return
随机字符串
但它不起作用。当我试图在数据库中保存哈希字符串时,它根本不会创建任何条目。如果我想保存随机字符串,它的效果非常好
我尝试过清理散列字符串,应用了strval()
,应用了$wpdb->insert
,其中我将其声明为字符串。什么都不管用!我甚至尝试将服务器资源增加到4GB ram、2V核心处理器。将每个php.ini资源限制增加到3GB。什么都不管用
这是一个完美工作的函数。但是,在这个函数中,我想将'verification\u code'=>$email\u verification
替换为'verification\u code'=>$email\u verification\u Hash
,但它不起作用。我想让它工作,使散列字符串进入数据库,并随机返回字符串
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';
}
}
这是一个愚蠢的错误,数据库列是VARCHAR(21)
,而散列字符串比这个长得多。我只是简单地将列更改为VARCHAR(255)
,现在它开始工作了