ActiveRecord Mysql选择列为Null

时间:2014-05-27 06:53:59

标签: php mysql codeigniter activerecord

我有这个查询:

  $this->db->select ( 'u.user_id as id, u.username, u.first_name as firstName, u.last_name as lastName,' . null . 'as client' );
  $this->db->from ( 'users u' );

但是在执行相同的操作时,它会显示空列。

还有

  $this->db->select ( 'u.user_id as id, u.username, u.first_name as firstName, u.last_name as lastName, null as client' );

在users表中将null作为列名称,并在未找到列时报告错误。

虽然直接执行到mysql时,查询会给出预期的输出

SELECT u.user_id as id, u.username, u.first_name as firstName, u.last_name as lastName, null as client FROM users u

2 个答案:

答案 0 :(得分:1)

您需要在select()

的第二个参数中传递FALSE
$this->db->select ( 'u.user_id as id, u.username, u.first_name as firstName, u.last_name as lastName, NULL as client' ,FALSE );
 $this->db->from ( 'users u' );

答案 1 :(得分:1)

试试这个:

  $this->db->select ( 'u.user_id as id, u.username, u.first_name as firstName, u.last_name as lastName',false);
  $this->db->from ( 'users u' );

false告诉不要逃避查询。