note 85820 added to pdo.query
| From: | oohall | Date: | Fri, 19 Sep 2008 05:52:08 +0000 |
| Subject: | note 85820 added to pdo.query | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-144534@lists.php.net to get a copy of this message | ||
Since query() dosn't support ? paramaters I hacked this up:
<?php
class MyPDO extends PDO
{
private $qcache; // prepared query cache
// Usage: $dbobject->query($sql, $args...)
public function pquery($sql)
{
if( is_object($this->qcache[$sql]))
{
$query = $this->qcache[$sql];
} else {
$query = $this->prepare($sql);
$this->qcache[$sql] = $query;
}
$args = func_get_args();
array_shift($args);
$query->execute($args);
return $query;
}
}
?>
Food for thought: If you're going though the results of a query and use this function to
perform another query of the same type (meaning same object) the results from the previous query
will be lost. Granted, this probably won't happen (often). but it should be noted.
----
Server IP: 117.104.160.194
Probable Submitter: 124.185.5.244
----
Manual Page -- http://www.php.net/manual/en/pdo.query.php
Edit -- https://master.php.net/note/edit/85820
Del: integrated -- https://master.php.net/note/delete/85820/integrated
Del: useless -- https://master.php.net/note/delete/85820/useless
Del: bad code -- https://master.php.net/note/delete/85820/bad+code
Del: spam -- https://master.php.net/note/delete/85820/spam
Del: non-english -- https://master.php.net/note/delete/85820/non-english
Del: in docs -- https://master.php.net/note/delete/85820/in+docs
Del: other reasons-- https://master.php.net/note/delete/85820
Reject -- https://master.php.net/note/reject/85820
Search -- https://master.php.net/manage/user-notes.php