我需要有关如何对 mysql php 准备好的语句使用 UUID 的帮助,它总是给我错误
user_id 在我的 mysql 5.6 上设置为二进制(16),在 phpmyadmin full Function 上有没有办法让我完成这项工作,
function create()
{
$query = "INSERT INTO " . $this->table_name . " SET
user_id = UNHEX(REPLACE(UUID(), '-','')),
name = :name,
email = :email,
password = :password";
$stmt = $this->con->prepare($query);
$this->name = htmlspecialchars(strip_tags($this->name));
$this->email = htmlspecialchars(strip_tags($this->email));
$this->password = htmlspecialchars(strip_tags($this->password));
$stmt->bindParam(':name', $this->name);
$stmt->bindParam(':email', $this->email);
$password_hash = password_hash($this->password, PASSWORD_BCRYPT);
$stmt->bindParam(":password", $password_hash);
if ($stmt->execute()) {
return true;
echo($stmt->errorInfo());
}
print_r($stmt->errorInfo());
return false;
}
这里使用了create函数
$user->name = $data->name;
$user->email = $data->email;
$user->password = $data->password;
if(
!empty($user->name) &&
!empty($user->email) &&
!empty($user->password)&&
$user->create()
){
http_response_code(200);
echo json_encode(array("message" => "User was created."));
}else{
http_response_code(400);
echo json_encode(array($user->create()));
echo json_encode(array("message" => "Unable to create user."));
}
错误的是
print_r($stmt->errorInfo());
给出的是
Array ( [0] => HY000 [1] => 1270 [2] => 操作“替换”时非法混合排序规则 (utf8_general_ci,COERCIBLE), (utf8_unicode_ci,COERCIBLE), (utf8_unicode_ci,COERCIBLE) ) [false]{ "message":"无法创建用户。"}
翻阅古今