note 73454 deleted from pdo.prepare by danbrown

From: Date: Wed, 23 Mar 2011 15:34:53 +0000
Subject: note 73454 deleted from pdo.prepare by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-178134@lists.php.net to get a copy of this message
Note Submitter: Greg MacLellan ---- A more versatile version of the below, but supporting an associative array and arbitrary number of fields: <?php public function matchCriteria($fields=null) { $db=DB::conn(); $sql=array(); $paramArray=array(); if(is_array($fields)) { foreach ($fields as $field=>$value)) { $sql[] = $field.'=?'; $paramArray[]=$value; } } $rs=$db->prepare('SELECT * FROM mytable'.(count($paramArray) ? ' WHERE '.join(' AND ',$sql) : '')); $result=$rs->execute($paramArray); if($result) { return $rs; } return false; } ?>

« previous php.notes (#178134) next »