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

Issue Type: Bug Created: 2009-02-15T16:01:38.000+0000 Last Updated: 2010-02-18T11:19:19.000+0000 Status: Resolved Fix version(s): Reporter: etaty (etaty) Assignee: Pieter Kokx (kokx) Tags: - Zend_Db

Related issues: - ZF-1398



(sorry for my English)

<pre class="highlight"> 
try {
    $db = Zend_Db::factory('Pdo_Mysql', 
        array('host' => '' , '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 :

<pre class="highlight"> 
<b>Fatal error</b>:  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 <b>..\Zend\Db\Statement\Pdo.php</b> on line <b>238</b><br></br>

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 !


Posted by Pieter Kokx (kokx) on 2010-02-18T10:57:10.000+0000

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

Have you found an issue?

See the Overview section for more details.


© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.