Vel Posted March 13, 2012 Share Posted March 13, 2012 Hey guys, I have come across what I think is one of the craziest bugs I have ever seen. I'm developing a site on my local machine using WAMP (version 2.2). I have a pretty standard database connection class but for some reason all of a sudden tonight it's stopped working. The code: if(!defined("IN_PHPBB")) { exit; } require 'config.php'; class db_conn { public $connection = NULL; function db_conn() { global $abchost, $abcname, $abcpasswd, $abcuser; if(!$this->connection = mysql_connect($abchost, $abcuser, $abcpasswd)) { echo "Error connecting to the database. Please check the config file."; if(defined('DEBUG')) { echo "<br />MySQL Error: " . mysql_error(); } exit; } if(!mysql_select_db($abcname, $this->connection)) { echo "Error selecting the database. Please check the config file."; if(defined('DEBUG')) { echo "<br />MySQL Error: " . mysql_error(); } exit; } } } $db_conn = new db_conn; Config.php contains nothing but the four variables for connecting to the db. Nothing has changed across either file but for some reason if I try to echo out the variables in the function they are all empty. Even stranger, the first part of the connection works (with 3 empty variables!), and it's mysql_select_db that's throwing an error. Why, completely out of the blue, with nothing changing, would the function not be able to read the variables any more. If I manually copy and paste the variables from the config file into the class function then it connects fine. Quote Link to comment https://forums.phpfreaks.com/topic/258854-require-help-explaining-why-connection-suddenly-has-stopped-working/ Share on other sites More sharing options...
RussellReal Posted March 13, 2012 Share Posted March 13, 2012 Well, If you're using WAMP, you probably don't have MySQL running, try restarting everything, if not, dump some errors and see exactly why its not working, and post the errors here and I can help you out further. Quote Link to comment https://forums.phpfreaks.com/topic/258854-require-help-explaining-why-connection-suddenly-has-stopped-working/#findComment-1327010 Share on other sites More sharing options...
Vel Posted March 13, 2012 Author Share Posted March 13, 2012 Well, If you're using WAMP, you probably don't have MySQL running, try restarting everything, if not, dump some errors and see exactly why its not working, and post the errors here and I can help you out further. I already tried restarting it with no results and the fact that I can post the variables in the function and everything works fine proves that MySQL is running fine. The only error I'm getting is the MySQL Error: No database selected. I have full error logging turned on and am getting 0 PHP errors. I'm really pulling my hair out over this one, any help is really appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/258854-require-help-explaining-why-connection-suddenly-has-stopped-working/#findComment-1327012 Share on other sites More sharing options...
RussellReal Posted March 13, 2012 Share Posted March 13, 2012 You are not selecting a database, you need to use mysql_select_db Quote Link to comment https://forums.phpfreaks.com/topic/258854-require-help-explaining-why-connection-suddenly-has-stopped-working/#findComment-1327014 Share on other sites More sharing options...
Vel Posted March 13, 2012 Author Share Posted March 13, 2012 You are not selecting a database, you need to use mysql_select_db Please actually read my OP and code before assuming I'm an idiot. Quote Link to comment https://forums.phpfreaks.com/topic/258854-require-help-explaining-why-connection-suddenly-has-stopped-working/#findComment-1327016 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.