How to set a value to NULL when using Zend_Db

When doing UPDATE and INSERT queries using Zend_Db, I often need to set the values ​​to NULL (not ``). However, the default behavior of Zend_Db :: insert () and Zend_Db :: update () seems to be that values ​​that are empty are translated into blank lines ('') and placed into the database as such.

Does anyone know how to actually force a NULL value to go into fields if the value is empty in php?

+5
source share
4 answers

Try setting the appropriate fields: new Zend_Db_Expr('NULL')

+19
source

I could always do this using PHP null:

$toUpdate = array('nullValue' => null, 'otherValue' => 'something');
Zend_Db::update($table, $toUpdate, $where);
+4

Johrn, PHP:

$value = null;
$what = array($columnName => $value);
$where = $this->_dbTableName->getAdapter()->quoteInto('Id = ?', $dbRecord->Id);
$this->_dbTableName->update($what, $where);

, NOT NULL, , FLOATs 0.00. , INT 0; -)

+1

Zend 2.4.7 , , William Lannen, . , getTable() Zend\Db\TableGateway:

public function fetch()
{
    $data['column_name1 = ?'] = 'column_value';
    $data[] = new \Zend\Db\Sql\Predicate\IsNull('column_name2');
    $resultSet = $this->getTable()->select($data);
    if (0 === count($resultSet) {
        return 'SomeExpectationOrException';
    } else {
        return $resultSet;
    }
}
0

All Articles