ZF-159: PDOException thrown "SQLSTATE[HY093]: Invalid parameter" on some queries due to bad parameter handling

Issue Type: Bug Created: 2006-06-29T09:53:26.000+0000 Last Updated: 2007-07-05T14:44:30.000+0000 Status: Closed Fix version(s): - 0.1.4 (29/Jun/06)

Reporter: Jayson Minard (jayson) Assignee: Gavin (gavin) Tags: - Zend_Db

Related issues: - ZF-140



from Namolovan Nicolae on the mailing list

<pre class="highlight">
class ServersTable extends Zend_Db_Table {
    protected $_name = 'servers';

$dbIns = array(

$table = new ServersTable();
$id = $table->insert($dbIns);

I get the follow error: "Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY093]: Invalid parameter number: parameter was not defined' in ..\Zend\Db\Adapter\Abstract.php:157"

This is because placeholders underscores are removed (in Db\Adapter\Abstract.php:124)

<pre class="highlight">
        // build the statement
        $sql = "INSERT INTO $table "
             . '(' . implode(', ', $cols) . ') '
             . 'VALUES (:' . str_replace("_", "", implode(', :', $cols)) . ')';

The result are:

<pre class="highlight">
INSERT INTO servers (name, os_ver) VALUES (:name, :osver)

My $dbIns don't contain any "osver" key, only "os_ver". That's why I get the PDO exception..

What is the solution to this problem ?


Posted by Jayson Minard (jayson) on 2006-06-29T09:54:37.000+0000

and from Ramon de la Fuente on the mailing list as well

I had the same question a few weeks ago - as I have not received answers I'm kicking this back into the list:

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY093]: Invalid parameter number: no parameters were bound'


<pre class="highlight">
  $db = Zend_Db::factory()

Turns out I had a question-mark in the data, which automatically turns into a placeholder even if you don't add a replacement array parameter. Is this intended?

Also, replacing the $db>query() with $db->insert(), I found that my column names (array_keys) get renamed without underscores. Again, is this intended?

Posted by Gavin (gavin) on 2006-06-29T11:48:04.000+0000

Duplicates [ZF-140]

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.