Issues

ZF-5793: Support of " `:col` " in PDO Mysql query

Description

(sorry for my English)

 
try {
    $db = Zend_Db::factory('Pdo_Mysql', 
        array('host' => '127.0.0.1' , 'username' => 'root' , 'password' => '' , 'dbname' => 'test',
            'driver_options' => array(PDO::MYSQL_ATTR_DIRECT_QUERY => 'SET NAMES \'utf8\'')));
} catch (Zend_Db_Exception $e) {    // on passe l'exception sous silence, elle sera gérée dans le système MVC plus tard 
}
Zend_Registry::set('Zend_Db', $db);
$result = $db->query("SELECT col as `:col` FROM  `table`");

Output :

 
Fatal error:  Uncaught exception 'Zend_Db_Statement_Exception' with message 'SQLSTATE[HY093]: Invalid parameter number: no parameters were bound' in C:\www\web\default\allgamestats\v2\Zend\Db\Statement\Pdo.php:238
Stack trace:
#0 ..\Zend\Db\Statement.php(283): Zend_Db_Statement_Pdo->_execute(Array)
#1 ..\Zend\Db\Adapter\Abstract.php(433): Zend_Db_Statement->execute(Array)
#2 ..\Zend\Db\Adapter\Pdo\Abstract.php(230): Zend_Db_Adapter_Abstract->query('SELECT ip as `:...', Array)
#3 ..starter.php(21): Zend_Db_Adapter_Pdo_Abstract->query('SELECT ip as `:...')
#4 {main}
  thrown in ..\Zend\Db\Statement\Pdo.php on line 238

I have localized this error, it's in class Zend_Db_Statement and protected function _parseParameters().

But the query works with : "SELECT col as ':col' FROM table" replace with -> ' '

I do not know if the use of `` is a convention of MySQL, but phpMyAdmin uses this !

Comments

This problem occurs because currently, all statements are runned as prepared statements. Which is already reported in ZF-1398.