note 73454 added to function.PDO-prepare
| From: | GregMacLellan at osu1 dot php dot net | Date: | Fri, 23 Feb 2007 18:51:40 +0000 |
| Subject: | note 73454 added to function.PDO-prepare | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-123784@lists.php.net to get a copy of this message | ||
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;
}
?>
----
Server IP: 216.235.15.211
Probable Submitter: 72.38.54.164
----
Manual Page -- http://www.php.net/manual/en/function.PDO-prepare.php
Edit -- https://master.php.net/note/edit/73454
Del: integrated -- https://master.php.net/note/delete/73454/integrated
Del: useless -- https://master.php.net/note/delete/73454/useless
Del: bad code -- https://master.php.net/note/delete/73454/bad+code
Del: spam -- https://master.php.net/note/delete/73454/spam
Del: non-english -- https://master.php.net/note/delete/73454/non-english
Del: in docs -- https://master.php.net/note/delete/73454/in+docs
Del: other reasons-- https://master.php.net/note/delete/73454
Reject -- https://master.php.net/note/reject/73454
Search -- https://master.php.net/manage/user-notes.php