您不能在 mysql 中添加true
或添加false
到 a中。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
asfalse
和1
astrue
更新:
您可以创建一个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
}
通过这种方式,您可以通过传递数组来解释任何您喜欢的东西0
,1
无论它是真还是假,活跃和不活跃,还是其他任何东西。$decode_set