Garrett Heinlen Tue Feb 07 11:25:19 -0500 2012

Subject: Can not connect to database on production server

Fatal error: Uncaught exception 'ActiveRecord\DatabaseException' with message 'exception 'PDOException' with message 'SQLSTATE[HY000] [2002] Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)' in /home/tgvia/ Stack trace: #0 /home/tgvia/ PDO->_construct('mysql:host=loca...', 'username', 'password', Array) #1 /home/tgvia/ ActiveRecord\Connection->_construct(Object(stdClass)) #2 /home/tgvia/ ActiveRecord\Connection::instance('mysql://usernam...') #3 /home/tgvia/ ActiveRecord\ConnectionManager::get_connection(NULL) #4 /home/tgvia/ ActiveRecord\Table->reestablish_connection(false) #5 /home/tgvia/ ActiveRecord\Table->__construct('Price') #6 /home/tgvia/ ActiveReco in /home/tgvia/ on line 241

This is my trace, and the code I am using is..

require_once 'ActiveRecord.php';
ActiveRecord\Config::initialize(function($cfg) {
'production' => 'mysql://user:/tg_registration'));


Any ideas how I can fix? The server is running 5.3 and I have run phpinfo(); and it seems to have PDO drivers for mysql databases. The site is running on dreamhost and I would appreciate any and all help.

Jasper Tey Mon Feb 13 09:42:23 -0500 2012

I've experienced this when the database server is down; but what I want to add is that the fatal error exposes the database password in plain text,

Stack trace: #0 /home/tgvia/ PDO->_construct('mysql:host=loca...', 'username', 'password', Array)

And that's not good :-|

How do we prevent that or hide that? Where do we catch it?

Nanne Huiges Mon Feb 13 10:06:37 -0500 2012

Not the complete sollution, but one thing: set your error-level to (0) on production.

You shouldn't be showing any of these errors to the user anyway. Lower your error_level on production servers as some sort of catch_all for problems like this! (basically: you should stop this error from happening, but you are manually catching everything you know can happen. This is good, but you can never list everything, so you should also have a catchall: in this case it is "never show errors".)

Be sure to keep your error_level 'sane' on your development machine.