Call to undefined method MDB2_Error::setFetchMode()

Jamie Hutber picture Jamie Hutber · Aug 14, 2014 · Viewed 8k times · Source

I am using PEAR's MDB2 to connect to my MySQL DB's.

I have never had a problem before but this particular host is causing me problems.

At first I thought it was the user credentials but I have tested on the same file with a standard MySQL code to connect successfully.

 //Error Code
 Fatal error: Call to undefined method MDB2_Error::setFetchMode() in /home/topazmar/public_html/db/db.php on line 15

 //Php Code
 $this->conn=MDB2::connect(array(
        'phptype'  => 'mysql',
        'username' => DATABASE_USR,
        'password' => DATABASE_PWD,
        'hostspec' => DATABASE_HOST,
        'database' => DATABASE_NAME,
    ));
    $this->conn->setFetchMode(MDB2_FETCHMODE_ASSOC); //Line 15

Edit

I outputting $this->conn with a dump

[0] => Array
            (
                [file] => /home/topazmar/public_html/db/MDB2.php
                [line] => 979
                [function] => PEAR_Error
                [class] => PEAR_Error
                [type] => ->
                [args] => Array
                    (
                        [0] => MDB2 Error: not found
                        [1] => -4
                        [2] => 1
                        [3] => 1024
                        [4] => unable to find package 'MDB2_Driver_mysql' file 'MDB2/Driver/mysql.php'
                    )

            )

I do have MDB2_Driver_mysql 1.4.1 installed along with PEAR and MDB2... Makes me confused, I don't imagine using modrewrites would change this at all.

Answer

Marek picture Marek · Aug 14, 2014

Your connection is failing and you get back error object (class MDB2_Error) instead of connection object (class extending MDB2_Driver_Common).

Use PEAR::isError($this->conn) to check if the connection succceeded.

[Edit - Hutber]

This Means You Haven't connected to the db, pw problems, user not privaliaged etc