您可以使用:
$this->db->from('person')->where('age is not null');
如果你好奇,这是如何发生看system/database/DB_active_rec.php
protected function _where($key, $value = NULL, $type = 'AND ', $escape = NULL)
{
...
if (is_null($v) && ! $this->_has_operator($k))
{
// value appears not to have been set, assign the test to IS NULL
$k .= ' IS NULL';
}
...
}
而且system/database/DB_driver.php
/**
* Tests whether the string has an SQL operator
*
* @access private
* @param string
* @return bool
*/
function _has_operator($str)
{
$str = trim($str);
if (! preg_match("/(\s|<|>|!|=|is null|is not null)/i", $str))
{
return FALSE;
}
return TRUE;
}
因此,您可以将第一个参数传递给where()
方法,如果此方法的第一个运算符有一个子字符串is not null
,它将保持不变。
要阅读更多 - CodeIgniter forum
希望这将有助于http://codeigniter.com/forums/viewthread/119444/P15 – sbaaaang
你设置允许空DEFAULT NULL mysql的选项,你的数据库字段? – sbaaaang
有用的论坛主题。 –