我遇到以下错误:
AES_ENCRYPT method not found.
请帮助我在 YII2 中使用此 SQL 方法。
public function beforeSave($insert) {
if (!parent::beforeSave($insert)) {
return false;
}
if($insert) {
$this->created_at = date('Y-m-d H:i:s');
}
$this->updated_at = date('Y-m-d H:i:s');
$this->name = AES_ENCRYPT("'.$this->name.'", "SECERT KEY");
return true;
}
最佳答案
因为这样调用它
$this->name = AES_ENCRYPT("'.$this->name.'", "SECERT KEY");
将假设它是一个 php
方法,并且会搜索可用的 php
函数,而您需要像运行 CONCAT
一样运行它>、SUM
或任何其他 MYSQL
函数。
您应该按以下方式将其与 \yii\db\Expression()
一起使用
$enc = new \yii\db\Expression('AES_ENCRYPT("'.$this->name.'","SECERT KEY")');
$this->name=$enc;
或简化它
$this->name=new \yii\db\Expression('AES_ENCRYPT("'.$this->name.'","SECERT KEY")');
希望对你有帮助。
关于php - Yii2:在插入数据库时使用mysql AES_ENCRYPT,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49448035/