Zend_Validate_Db_RecordExists in Zend Framework 1.10+

Zend_Validate_Db_RecodExists is an extremely useful validator in Zend Framework when you’d like to be sure that a give row exists. Now it seems to be even better. Before you could check for a specific row by only comparing a value to the specified column:

$validator = new Zend_Validate_Db_RecordExists('db_table_name', 'column_name');
if ($validator->isValid(122)) {
   ...
}

which made it useless when you’d like to compare by more than one column. Now this is changed and you can even exclude given rows by adding an exclude clause.

$validator = new Zend_Validate_Db_NoRecordExists(
    array(
        'table' => 'users',
        'field' => 'username',
        'exclude' => array(
            'field' => 'id',
            'value' => $user_id
        )
    )
);

Related posts:

  1. Using Zend Framework validators – Zend_Validate_Db_RecordExists
  2. MySQL Expressions in Zend Framework
  3. JSON and Zend Framework? – Zend_Json
This entry was posted in micro tutorial, PHP, zend framework and tagged , , , , , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">