mindspin311 Posted February 2, 2008 Share Posted February 2, 2008 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); ?> Link to comment https://forums.phpfreaks.com/topic/88987-peardb-problem-cant-connect-to-db-whats-wrong/ Share on other sites More sharing options...
mindspin311 Posted February 2, 2008 Author Share Posted February 2, 2008 I should also note that this is a website with many many pages. Each page that uses the database starts with require 'database/dbconnect.php'; Link to comment https://forums.phpfreaks.com/topic/88987-peardb-problem-cant-connect-to-db-whats-wrong/#findComment-455763 Share on other sites More sharing options...
mindspin311 Posted February 2, 2008 Author Share Posted February 2, 2008 After consulting tutorials and other code, I think it might be a problem with the database itself. Link to comment https://forums.phpfreaks.com/topic/88987-peardb-problem-cant-connect-to-db-whats-wrong/#findComment-455791 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.