Cant connect to MySQL any more


#1

Hi
I have a Smarty-based site on propel.dreamhost.com and today I’m finding a blank page… turning on smarty debugging I get

Warning: mysql_connect() [function.mysql-connect]: Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’ (2) in /home/.nittany/beezkneez/(mywebsite)/classes/db.class.php on line 40

I can connect to phpMyAdmin fine, and in my smarty config I have the correct values for host, username, password and database name (and I’m not using localhost for the MySQL hostname). I havent changed anything code-wise over Christmas.

I wonder if it’s an environment thing though because line 2 of the error is:

“Could not connect to”

with no server name specified.

The Smarty line in db.class.php is
$sqllink = mysql_connect ($server, $username, $password) or die (“Could not connect to $server\n”);

This is called from index.php:

$root = “”;
require($root.“config.php”);
require $root.‘libs/Smarty.class.php’;
include($root.“classes/db.class.php”);
$db = new DB();
$sqllink = $db->connect($sqlhost, $sqlusername, $sqlpassword);
$db->use_db($sqldatabase);

I thought I would try setting the $root variable, to
/home/beezkneez/(mywebsite)/
… no luck. Also, if I manually add the server/username/pass to the db.class.php connection code I then get the error:

Fatal error: Cannot instantiate non-existent class: db in /home/.nittany/beezkneez/(mywebsite)/index.php on line 29

I get this error even if I set the $host variable, so the include line
include($root.“classes/db.class.php”);
should work. And classes/db.class.php does exist.

Is this a problem with the server? Can anyone suggest other things to check?

cheers

Lucas


#2

I think I can clear up some of your problems but perhaps not all.

The way dreamhost has php configured all form submissions go straight to variables…what I mean is when someone submits a form with a variable with a name of “age” the variable $age is automatically defined whereas normally you would have to specify $_GET[“age”] or $_POST[“age”]. The adverse result of this is that you will never see an error specifying that a variable is undefined.
Now, what this means to you: it appears that the variable $server, $username,$password…are undefined in the scope of db.class.php One thing that you should check is that if you define the $server variable in your config.php file that you have the line “global $server;” in your db.class.php file.

By adding the code directly into the db.class.php file all you did was get to your next problem. but I dont really know how to help you without seeing the rest of the DB class…


#3

Thanks Airhead315 - turns out it was a blank config file at DreamHost’s end and it’s all good now. But the call to the class function was correctly passing parameters and it’s working now.

thanks for the help

cheers