在带有绑定变量的预处理语句中使用 AES_ENCRYPT

Using AES_ENCRYPT in Prepared Statement with Bind Variables

想要加密特定的数据变量,但不断得到 "PHP Fatal error: Call to undefined function AES_ENCRYPT()..."

研究让我暗示它使用的是 PHP 而不是 MySQL?

$key="xyz";

$stmt = mysqli_prepare($mysqli, "INSERT INTO details (FirstName, LastName, EncryptThis) VALUES (?,?,?)");

if ($stmt === false) {
        trigger_error('Statement failed! ' . htmlspecialchars(mysqli_error($mysqli)), E_USER_ERROR);
    }                      

$bind = mysqli_stmt_bind_param($stmt, "sss", $FirstName, $LastName,  AES_ENCRYPT('$EncryptThis','$key'));

        if ($bind === false) {
        trigger_error('Bind param failed!', E_USER_ERROR);
    }                  

$exec = mysqli_stmt_execute($stmt);

正在数据库中使用 varbinary...

尝试过

的各种用途
AES_ENCRYPT('$EncryptThis','$key')

EG

AES_ENCRYPT($EncryptThis,$key) 

等等等等

MySQL 期望 values 作为绑定参数传递。不是函数名称或其他 SQL 表达式。只是 .

如果你想调用 MySQL AES_ENCRYPT 函数,它需要作为 SQL 文本的一部分出现(作为 SQL 语句准备的字符串).函数名称不能作为绑定参数的一部分传递。

像这样:

 "INSERT ... VALUES ( ? , ? , AES_ENCRYPT( ? , ? ) )" 

 mysqli_stmt_bind_param($stmt, "ssss", $FirstName, $LastName, $EncryptThis, $key);