Our Blog

News, thoughts & useful links

Contact: Skype , email or call
+44 (0) 131 556 6818

Basic guide to using Null and Not Null in Propel queries

January 4th, 2009 by Anton

Here is a quick hint on how to use Propel and its Criteria class to generate queries that need to have Null or Not Null in WHERE clauses:


<?php
$c = new Criteria();
$c->add(TablePeer::TABLE_ID, null, Criteria::NOT_EQUAL);

// this is the same as above
$c = new Criteria();
$c->add(TablePeer::TABLE_ID, null, Criteria::ISNOTNULL);

// ======================================

// for equality checking do this:
$c = new Criteria();
$c->add(TablePeer::TABLE_ID, null);

// or
$c = new Criteria();
$c->add(TablePeer::TABLE_ID, null, Criteria::EQUAL);

// or
$c = new Criteria();
$c->add(TablePeer::TABLE_ID, null, Criteria::ISNULL);

?>


Comments are closed.