你不能在mysql中添加true
或false
到TINYINT
。你應該做1
或0
這樣
$new_record = array(
"name" => "Don",
"is_awesome" => 1 //1 means it's true
);
$query = $this->db->insert('table_name', $new_record);
則只是當你把它拿來考慮0
爲false
和1
作爲true
更新: 你可以創建一個函數調用tinyint_decode
這樣的:
public function tinyint_decode($result = array(), $decode_set = array())
{
//$result is what you got from database after selecting
//$decode_set is what you would like to replace 0 and 1 for
//$decode_set can be like array(0=>'active', 1=>'inactive')
//after fetching the array
$result->is_awesome = ($result->is_awesome == 1 ? $decode_set[1] : $decode_set[0]);
return true;// or anything else
}
這樣你就可以解釋t 0
和1
由你喜歡的任何東西,無論是真的還是假的,活動的還是非活動的,或者只是通過傳遞$decode_set
數組。
使用「Y」或「N」的1個字符的mysql列是一個可怕的想法。任何時候你返回這一行,並檢查大多數語言,如果它是真或假,你會得到真正的字符串存在。 –
也看起來像MySQL有一個布爾類型:http://dev.mysql.com/doc/refman/5.0/en/numeric-type-overview.html 也許我應該使用 –
是的你是對的關於1字符thingy。我通常做1和0. –