我试图将字符保存到我的mysql数据库中,但是一旦我尝试插入这些ââ¬Å这样的字符,我的mysql就会中断。
我的桌子看起来像这样
CREATE TABLE `table` (
`name` varchar(255) CHARACTER SET latin1 COLLATE latin1_general_cs DEFAULT NULL,
`email` varchar(255) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
我从CSV文件读取的PHP代码如下所示。
$file = 'http://localhost/file.csv';
$fileHandler=fopen($file,'r');
if($fileHandler){
while($line=fgetcsv($fileHandler,1000)){
$str = preg_split('/\s+/', trim($line[0]));
$name = trim($str[0]);
$email = trim($str[1]);
$sql = "INSERT INTO `table` (`name`, `email`) VALUES ('".$name."', '".$email."' )";
Yii::app()->db->createCommand($sql)->query();
}
}
一旦我到达CSV文件中的这一行,它就会不断中断
"Paul Paul.D@blablabla.com"
更新:
添加了一个尝试捕获,内容如下
CDbException Object ( [errorInfo] => Array ( [0] => 22001 [1] => 1406 [2] => Data too long for column 'name' at row 1 ) [message:protected] => CDbCommand failed to execute the SQL statement: SQLSTATE[22001]: String data, right truncated: 1406 Data too long for column 'name' at row 1. The SQL statement executed was: INSERT INTO `3lite` (`name`, `email`) VALUES ('Paul��', 'Paul.D@blablabla.com' ) [string:Exception:private