Andrew
Andrew

Reputation: 238717

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

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 what 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?

Upvotes: 1

Views: 4305

Answers (1)

Brian Fisher
Brian Fisher

Reputation: 23989

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);
}

Upvotes: 1

Related Questions