Reputation: 743
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.
Upvotes: 1
Views: 6908
Reputation: 983
I had this very problem as well. What happens is that PEAR DB is tailored to work with PHP 4.X class syntax, while GoDaddy obviously has PHP 5.X installed — and this means that you get these errors. While they're not labeled as "fatal" somehow they behave as fatal errors — the methods simply are not called.
If you have access to the PEAR source, you have no other option but to go through each function that appears on the logs, one by one, and add the "static" keyword before the function declaration. It's a pain, but it's the only option. I've just done that today with success — I have a very old application to maintain that still requires PEAR DB to operate, and the latest auto-upgrades of PHP (currently PHP 5.3.X) had broken the database connectivity. Porting the whole application to use MDB2 (the recommended choice) was not an option, so adding a dozen or two "static" keywords did the trick for me.
But if you're starting a project from scratch, and have no legacy code to maintain, I definitely recommend that you abandon DB and move on to MDB2 instead.
Upvotes: 0
Reputation: 360702
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.
Upvotes: 1
Reputation: 94173
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.
Upvotes: 1