开发者

How to select rows where a column value is empty/null using Zend_Db?

开发者 https://www.devze.com 2022-12-10 15:10 出处:网络
I have an SQLite database, eventually will be a MySQL database and I\'m using Zend Framework. I\'m trying to fetch all the rows in a table where the \'date_accepted\' column is empty/null/doesn\'t hav

I have an SQLite database, eventually will be a MySQL database and I'm using Zend Framework. I'm trying to fetch all the rows in a table where the 'date_accepted' column is empty/null/doesn't have a value. This is wha开发者_开发百科t I have so far:

public function fetchAllPending()
{
    $select = $this->getDbTable()->select();
    $select->where('date_accepted = ?', 'null');
    return $this->fetchAll($select);
}

What am I doing wrong? How would you write this in plain SQL, and/or using Zend_Db_Select?


Two possible issues I see. What is the function getDbTable? If your class inherits from Zend_Db_Table that function shouldn't be necessary. Second maybe you should try IS NULL instead of = null with quoting null into the query.

public function fetchAllPending()
{
        $select = $this->select()->where('date_accepted IS NULL');
        return $this->fetchAll($select);
}
0

精彩评论

暂无评论...
验证码 换一张
取 消