sqlSTATE[HY000]: General error: 1366 Incorrect string value: '\xE4\xD5\xABtZM...' for column 'Name'
我已经阅读了Stackoverflow中发布的所有答案,并且还将Googled的问题,但所有提出的解决方案已经在我的代码.数据库,表和所有col都有排序规则utf8_general_ci.下面你可以看到相关代码:
> Application.ini来看看如何设置连接
> Database.PHP看看我如何检索数据库连接
> Model.PHP看看我如何尝试在数据库中插入数据
> encrypt()来查看我如何使用AES类加密数据
>表定义(如果知道所有都在utf8中是不够的)
的application.ini
resources.db.adapter = "Pdo_MysqL" resources.db.params.charset = "utf8" resources.db.params.host = "localhost" resources.db.params.username = "********" resources.db.params.password = "********" resources.db.params.dbname = "dbname"
为database.PHP
public static function getDb() { if (self::$Db === NULL) self::$Db = Zend_Db_Table::getDefaultAdapter(); return self::$Db; }
model.PHP
$Values = array( 'Id' => $this->Id,'Name' => $this->Name,'CreationDate' => $this->CreationDate,); $RowChanged = $Db->insert('TABLENAME',$Values);
加密()
public static function encrypt($Data,$EncryptionKey) { $AES = new Crypt_AES(); $AES->setKey($EncryptionKey); return $AES->encrypt($Data); }
表
CREATE TABLE IF NOT EXISTS `table` ( `Id` mediumint(8) unsigned NOT NULL,`Name` varchar(200) DEFAULT NULL,`CreationDate` date NOT NULL,PRIMARY KEY (`Id`),) ENGINE=InnoDB DEFAULT CHARSET=utf8;
问题:我如何解决问题并将数据存储到数据库中?
在MysqL站点上有一个不太清楚的explanation.
Many encryption and compression functions return strings for which the result might contain arbitrary byte values. If you want to store these results,use a column with a VARBINARY or BLOB binary string data type. This will avoid potential problems with trailing space removal or character set conversion that would change data values,such as may occur if you use a nonbinary string data type (CHAR,VARCHAR,TEXT).