For those using Zend 2, if you want to check if a user exists with the id and email data in the users table, this is possible.
First you create a select object that will be used as a parameter for the Zend\Validator\Db\RecordExists
$select = new Zend\Db\Sql\Select(); $select->from('users') ->where->equalTo('id', $user_id) ->where->equalTo('email', $email);
Now create a RecordExists object and check for the existence of this path.
$validator = new Zend\Validator\Db\RecordExists($select); $validator->setAdapter($dbAdapter); if ($validator->isValid($username)) { echo 'This user is valid'; } else { //get and display errors $messages = $validator->getMessages(); foreach ($messages as $message) { echo "$message\n"; } }
This sample is from white paper ZF2
source share