Jump to content

Pear::DB problem.. can't connect to db.. What's Wrong?????


mindspin311

Recommended Posts

I'm having a problem connecting to a database. I have this website done in PHP and MySQL using Pear::DB (before it was standard with PHP 5) and trying to host it. I used my hosts site to add a database which is named 'minds004_student'. It doesn't have any data in it yet, but I still should be able to connect to the database. It just says 'DB Error: connect failed' after my error msg. I'm not sure what's wrong and it's been a few years since I've worked on this site or anything involving php and mysql. I've checked and the database, username, password, and engine appear to be all correct. And I just plugged in the domain as the host. I use omnis.com to host my site if anyone has had similar problems with them. I switch the require_once 'DB.php' to another name and it gives another error, so I'm sure it's not on Pear::DB's end.

 

Here's the code:

 


<?php
//PEAR::DB allows database abstraction.
//We can easily switch to a different type of database by changing 
//the $datasource variable.
//More specific information for this at:
//http://pear.php.net/manual/en/package.database.db.intro-dsn.php

//require the PEAR::DB classes.
require_once 'DB.php';

$db_engine = 'mysql';
$db_user = 'minds004_student';
$db_pass = 'password';
$db_host = 'mindspingames.com';
$db_name = 'minds004_student';

$datasource = $db_engine.'://'.
              $db_user.':'.
              $db_pass.'@'.
              $db_host.'/'.
              $db_name;

$db_object = DB::connect($datasource, true);

//Assign database object in $db_object, 
//if the connection fails $db_object will contain
//the error message.
//If $db_object contains an error:
//error and exit.
if(DB::isError($db_object)) {
  echo "Not working...";
  die($db_object->getMessage());
}

$db_object->setFetchMode(DB_FETCHMODE_ASSOC);
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.