tags:

views:

51

answers:

2

Im having a little trouble connecting to a database with PEAR on my GoDaddy hosting account. I am able to connect to my database with the standard mysql_connect.

I have downloaded the DB package from: http://pear.php.net/package/DB

Firstly I have included the package (which works):

include 'libs/pear/db/DB.php';

Then I connect with:

$dsn = array(
    'phptype'  => "mysql",
    'hostspec' => $hostname,
    'database' =>  $dbname,
    'username' => $username,
    'password' => $password
);

$conn = DB::connect($dsn);

if (DB::isError ($conn))
     die ("Cannot connect: " . $conn->getMessage () . "\n");

However, it does not work. In fact if I put a die inbetween $conn = DB::connect($dsn); and if (DB::isError ($conn)), it does not show. Its like the script ends on the DB::connect.

Ive tried turning errors on with:

ini_set('display_errors',1);
error_reporting(E_ALL|E_STRICT);

And I get:

Strict Standards: Non-static method DB::connect() should not be called statically in /path/t.php on line 27

Strict Standards: Non-static method DB::parseDSN() should not be called statically in /path/DB.php on line 520

Which aren't fatal errors so it shoudldn't cause the script to die??

I cannot get to the error logs as GoDaddys web interface just sends me to a not found page.

Am I missing packages? Please advise! Thanks.

A: 

PEAR::DB has been superceded by MDB2, and had not been updated since 2007. A bug report about the error messages you encountered was filed, but never resolved.

You might want to try using PDO instead.

Daniel Vandersluis
A: 

DB's obsolete, and will throw quite a few warning when running in strict mode on a standard modern PHP install. For that matter, so will its successor, MDB2. The warnings aren't fatal, they're just pointing out that the ::connect() "method" is set up incorrectly.

It'll still work, just ignore the warnings. But consider upgrading to something more modern like PDO.

Marc B