Zend: How to use "not equal" in a WHERE clause?

I use the following zend code to select all the data from a table where verified = 1, and it works for me.

$table = $this->getDbTable();
$select = $table->select();
$select->where('verified = 1');
$rows = $table->fetchAll($select);

No. I want to select all the data from this table where verified is not equal to '1'. I tried the following methods, but it does not retrieve data.

$select->where('verified != 1');
$select->where('verified <> 1');
$select->where('verified != ?', 1);

The data structure for the checked column is:

Field: verified
type: varchar(45)
Collation: utf8_bin         
NULL: Yes   
Default: NULL  

Any idea how to use the not equal operator in a WHERE clause in Zend? Thanks

+3
source share
5 answers

MySQL <=>, true, . false, , null.

$select->where('verified <=> 1');

. SQL : IS NOT DISTINCT FROM, , MySQL <=>.

+4
$select->where('verified != ?', 1);

:

    $query = $this->getDb()->select();
    $query->from('title', array('title_id' => 'id', 'title', 'production_year', 'phonetic_code'))
            ->where('kind_id = 1')
            ->where('title = ?', trim($title))
            ->where('production_year != ?', '2009')
            ->limit(1)
            ;

IMDB. .

+5

varchar, , where verified != '1' or verified is null

+2

, ? int string? SQL, ZEND, . - .

$table = $this->getDbTable();
$select = $table->select();
$select->where('verified = 1');
echo sprintf("sql %s",$select);
$rows = $table->fetchAll($select);
+1

:

$select->where('verified != ?', '1');

. .

0

Source: https://habr.com/ru/post/1726117/


All Articles