0

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.

Jamie Hutber
  • 26,790
  • 46
  • 179
  • 291

3 Answers3

2

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

Jamie Hutber
  • 26,790
  • 46
  • 179
  • 291
Marek
  • 7,337
  • 1
  • 22
  • 33
  • `Strict Standards: Non-static method PEAR::isError() should not be called statically, assuming $this from incompatible context in` Not ideal, I don't fully see why it won't let me do this, but there u go – Jamie Hutber Aug 14 '14 at 09:38
  • Maybe there's now another way to check in PEAR error was returned, I haven't touched PEAR in long time. – Marek Aug 14 '14 at 09:40
  • I'm thinking maybe I should avoid it :) – Jamie Hutber Aug 14 '14 at 09:46
  • You can use `$this->conn instanceof PEAR_Error` instead. – Marek Aug 14 '14 at 09:50
  • I think got the error, almost less helpful :) but yours ` Parse error: syntax error, unexpected 'PEAR' (T_STRING) in /home/topazmar/public_html/db/db.php on line 19` See updated question – Jamie Hutber Aug 14 '14 at 10:03
  • Back here again.... On my own question... New machine, but I'm still getting the error and the answer doesn't help me sadly. Any ideas @Marek – Jamie Hutber Feb 25 '15 at 14:56
1

In case someone sees this thread and they did install MDB2 and the db drivers correctly: I had the same issue and it turned out I had set insufficient permissions for the db user. Durrr

Ginja Ninja
  • 395
  • 1
  • 6
  • 15
0

So for me what fixed it was as simple as installing the MDB2 library from pear.

Assuming you already have PEAR installed:

pear install MDB2 
pear install MDB2#mysql

From a terminal/cmd window, then I was good to go.

Jamie Hutber
  • 26,790
  • 46
  • 179
  • 291
  • You should not change your questions but ask a new one. Your new problem and answer are unrelated to the original. – Marek Feb 26 '15 at 16:30
  • But I don't think the question changed...I think your answer doesn't explain how to fix it, ekk sorry. – Jamie Hutber Feb 26 '15 at 16:32
  • It did change: first problem was you were getting `MDB2_Error` object. This also means `MDB2` was installed. After moving to new server you got another problem: `MDB2` was not installed. – Marek Feb 26 '15 at 16:35
  • +1 :) Ok, I was getting the exact same error `Call to undefined method MDB2_Error::setFetchMode()` And I don't see the answer helping me, but either way, if anybody searches this problem they'll have both answers to help them now :) – Jamie Hutber Feb 26 '15 at 16:47
  • Can't plus one myself! Needed it again – Jamie Hutber Mar 04 '15 at 17:00
  • lol still back here in 2022!! – Jamie Hutber Apr 13 '22 at 11:23