ZF-9663: Empty exception message with incorrect parameters for db2_execute()


PHP issues a warning when the parameter count is wrong for db2_execute (line 202 in Zend/Db/Statement/Db2.php). But it is quieted with '@'. That's fine, but db2_stmt_errormsg() and db2_stmt_error() never return anything. The exception message is empty as well.

I predict this is an issue with the PECL module upstream.

The following code produces:

header('Content-type: text/plain');

require_once 'Zend/Db.php';

try {
  $db = Zend_Db::factory('Db2', array('host' => '',
                                      'username' => 'user',
                                      'password' => '****',
                                      'dbname' => 'database');

  $stmt = $db->select()
      ->from(array('t' => 'table'),
      ->where('name = ?');

  $result = $db->fetchAll($stmt, array(/* warning condition */));

  foreach ($result as $row) {
    foreach ($row as $col => $val) {
      printf("  %s: %s\n", $col, $val);
} catch (Zend_Exception $e) {
  echo 'Caught exception of type: ' . get_class($e) . "\n";
  echo 'Error message: ' . $e->getMessage() . "\n";

Here's the result:

Caught exception of type: Zend_Db_Statement_Db2_Exception
Error message: 

The Pdo_Mysql driver does this:

Caught exception of type: Zend_Db_Statement_Exception
Error message: SQLSTATE[HY093]: Invalid parameter number: number of bound
variables does not match number of tokens


I've posted a bug to the ibm_db2 PECL extension.

Cross your fingers!