note 85820 deleted from pdo.query by philip
| From: | philip@php.net | Date: | Wed, 26 Feb 2014 00:04:00 +0000 |
| Subject: | note 85820 deleted from pdo.query by philip | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-198712@lists.php.net to get a copy of this message | ||
Note Submitter: oohall [AT] gmail [DOT] com
----
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.