Jump to content

Require help explaining why connection suddenly has stopped working


Recommended Posts

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.

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.

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.