php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #48773 Incorrect error when setting PDO::ATTR_STATEMENT_CLASS with ctor_args
Submitted: 2009-07-02 13:10 UTC Modified: 2009-07-19 18:57 UTC
From: saschagros at gmail dot com Assigned: felipe (profile)
Status: Closed Package: PDO related
PHP Version: 6CVS-2009-07-02 (snap) OS: Linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: saschagros at gmail dot com
New email:
PHP Version: OS:

 

 [2009-07-02 13:10 UTC] saschagros at gmail dot com
Description:
------------
I'm getting the following error when the ATTR_STATEMENT_CLASS option is set...

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000]: General error: PDO::ATTR_STATEMENT_CLASS requires format array(classname, array(ctor_args)); the classname must be a string specifying an existing class' in ..../drupal7/includes/database/database.inc:338

The same configuration works for PHP 5.2 and 5.3

The reproduce code is the constructor of the DatabaseConnection class of Drupal 7, see also http://cvs.drupal.org/viewvc.py/drupal/drupal/includes/database/database.inc?revision=1.57&view=markup

Reproduce code:
---------------
  function __construct($dsn, $username, $password, $driver_options = array()) {
    // Because the other methods don't seem to work right.
    $driver_options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_EXCEPTION;

    // Call PDO::__construct and PDO::setAttribute.
    parent::__construct($dsn, $username, $password, $driver_options);

    // Set a specific PDOStatement class if the driver requires that.
    if (!empty($this->statementClass)) {
      $this->setAttribute(PDO::ATTR_STATEMENT_CLASS, array($this->statementClass, array($this)));
    }
  }


Expected result:
----------------
The connection can be established....

Actual result:
--------------
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000]: General error: PDO::ATTR_STATEMENT_CLASS requires format array(classname, array(ctor_args)); the classname must be a string specifying an existing class' in ..../drupal7/includes/database/database.inc:338
Stack trace:
#0 .../drupal7/includes/database/database.inc(338): PDO->setAttribute(13, Array)
#1 .../drupal7/includes/database/mysql/database.inc(36): DatabaseConnection->__construct('mysql:host=loca...', 'd7', 'd7', Array)
#2 /.../drupal7/includes/database/database.inc(1350): DatabaseConnection_mysql->__construct(Array)
#3 .../drupal7/includes/database/database.inc(1218): Database::openConnection('default', 'default')
#4 .../drupal7/includes/database/database.inc(1793): Database::getConnection('default')
#5 .../drupal7/includes/bootstrap.inc(1242): db_query('SELECT 1 FROM {...', Array)


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-07-19 18:56 UTC] felipe@php.net
Fixed in SVN.

Thanks.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Fri May 09 20:01:27 2025 UTC