在CI架構下存入漢字 報資料庫錯誤
這是代碼:$comData = array( 'textArea' => $textArea, 'commentID' => $newComID, 'postID' => $newPostID, );$this->db->insert('COMMENTMETA',$comData);下面是報錯資訊:Error Number: 1366
Incorrect string value: '\xE6\xB5\x8B\xE8\xAF\x95' for column 'textArea' at row 1
INSERT INTO COMMENTMETA (textArea, commentID, postID) VALUES ('測試', 8, 28)
Filename: F:\code\CI\system\database\DB_driver.php
Line Number: 330
資料庫編碼:Mysql的編碼都是utf8
回複內容:
在CI架構下存入漢字 報資料庫錯誤
這是代碼:$comData = array( 'textArea' => $textArea, 'commentID' => $newComID, 'postID' => $newPostID, );$this->db->insert('COMMENTMETA',$comData);下面是報錯資訊:Error Number: 1366
Incorrect string value: '\xE6\xB5\x8B\xE8\xAF\x95' for column 'textArea' at row 1
INSERT INTO COMMENTMETA (textArea, commentID, postID) VALUES ('測試', 8, 28)
Filename: F:\code\CI\system\database\DB_driver.php
Line Number: 330
資料庫編碼:Mysql的編碼都是utf8
看下錶是否為utf-8,這是在建立表的時候可選的屬性。
update:
我仔細看了一下,你的model看起來是不符合CI規範的,使用了數組。正確的應該是:
$this->[鍵名] = $this->input->post('***');
另外你可以看看mysql的data檔案夾裡面的對應庫的檔案夾裡面的設定檔,那個必須是utf-8.
你的只說明了你的mysql環境是utf8的,不能代表你插入的那個表以及那些欄位也是utf8編碼的,此外,檢查下你檔案的編碼(或者說插入的資料的編碼)是否是utf8
用iconv()轉換一下插入字串的編碼
見資料庫相關CI手冊
檢查這一行$db['default']['char_set'] = "utf8";