From: Operating system: linux PHP version: 5.3.6 Package: PDO related Bug Type: Feature/Change Request Bug description:query() optionaly prepared and PDO::PARAM_FIELDNAME(quoting)
Description: ------------ I like prepared statements and its templating. Since query returns a statement, why not making it a prepared one, when the second parameter is an array, and execute it directly... Example: See my exPDO-Class at the bottom. Since mysql quotes fieldnames(and tablenames) different then standardconform sqlservers, it is not easy to write/generate sql that work everywhere... Eg. postgre lowercases fieldnames when they are not quoted in "... Mysql wants `... I help my self by deriving from PDO and overwrite quote... public function quote($txt,$parameter_type = PDO::PARAM_STR ){ if($parameter_type == "12345"){ if($this->getAttribute(PDO::ATTR_DRIVER_NAME) == 'mysql'){ return '`' . $txt . '`'; }else{ return '"' . $txt . '"'; } }else{ return parent::quote($txt,$parameter_type); } } By the way: Here is my hole extention.... Now it is possible to see all the executed querys, and the time it took to get the result.... <?php class extPDO extends PDO{ public $query_count = 0; public $exec_count = 0; public $prepared_count = 0; public $query_time = 0; public $sqls = array(); public function __construct($dsn, $username, $passwd, $options=array()){ parent::__construct($dsn, $username, $passwd, $options); self::setAttribute(PDO::ATTR_STATEMENT_CLASS, array("extPDOStatement",array($this))); } public function query($statement,$args = array()){ $this->query_count++; if(is_array($args)){ if(empty($args)){ $this->sqls[] = 'q: '.$statement; $start = microtime(true); $res = parent::query($statement); $this->query_time += microtime(true) - $start; return $res; }else{ //keine zeitmessung da diese durchs statement übernomen wird $res = self::prepare($statement); $res->execute($args); $this->prepared_count--; return $res; } }else{ $res = parent::prepare($statement); $res->execute(array($args)); $this->prepared_count--; return $res; } } public function exec($statement,$args = array()){ $this->exec_count++; if(is_array($args)){ if(empty($args)){ $this->sqls[] = 'e: '. $statement; $start = microtime(true); $res = parent::exec($statement); $this->query_time += microtime(true) - $start; return $res; }else{ $res = self::prepare($statement); $res->execute($args); $this->prepared_count--; return $res->rowCount(); } }else{ $res = self::prepare($statement); $res->execute( array($args) ); $this->prepared_count--; return $res->rowCount(); } } public function quote($txt,$parameter_type = PDO::PARAM_STR ){ if($parameter_type == "12345"){ if($this->getAttribute(PDO::ATTR_DRIVER_NAME) == 'mysql'){ return '`' . $txt . '`'; }else{ return '"' . $txt . '"'; } }else{ return parent::quote($txt,$parameter_type); } } public function prepare($statement,array $options = array()){ return parent::prepare($statement,$options); } } class extPDOStatement extends PDOStatement{ private $db; protected function __construct($db){ $this->db = $db; } public function execute(array $input_parameters = array()){ $this->db->sqls[] = 'p: '. $this->queryString; $this->db->prepared_count++; $start = microtime(true); $res = parent::execute($input_parameters); $this->db->query_time += microtime(true) - $start; return $res; } } ?> -- Edit bug report at http://bugs.php.net/bug.php?id=54861&edit=1 -- Try a snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=54861&r=trysnapshot52 Try a snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=54861&r=trysnapshot53 Try a snapshot (trunk): http://bugs.php.net/fix.php?id=54861&r=trysnapshottrunk Fixed in SVN: http://bugs.php.net/fix.php?id=54861&r=fixed Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=54861&r=needdocs Fixed in release: http://bugs.php.net/fix.php?id=54861&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=54861&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=54861&r=needscript Try newer version: http://bugs.php.net/fix.php?id=54861&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=54861&r=support Expected behavior: http://bugs.php.net/fix.php?id=54861&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=54861&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=54861&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=54861&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=54861&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=54861&r=dst IIS Stability: http://bugs.php.net/fix.php?id=54861&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=54861&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=54861&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=54861&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=54861&r=mysqlcfg