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/tgregister.com/test/lib/Connection.php:239 Stack trace: #0 /home/tgvia/tgregister.com/test/lib/Connection.php(239): PDO->_construct('mysql:host=loca...', 'username', 'password', Array) #1 /home/tgvia/tgregister.com/test/lib/Connection.php(101): ActiveRecord\Connection->_construct(Object(stdClass)) #2 /home/tgvia/tgregister.com/test/lib/ConnectionManager.php(33): ActiveRecord\Connection::instance('mysql://usernam...') #3 /home/tgvia/tgregister.com/test/lib/Table.php(103): ActiveRecord\ConnectionManager::get_connection(NULL) #4 /home/tgvia/tgregister.com/test/lib/Table.php(80): ActiveRecord\Table->reestablish_connection(false) #5 /home/tgvia/tgregister.com/test/lib/Table.php(61): ActiveRecord\Table->__construct('Price') #6 /home/tgvia/tgregister.com/test/lib/Model.php(737): ActiveReco in /home/tgvia/tgregister.com/test/lib/Connection.php on line 241

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

require_once 'ActiveRecord.php';
ActiveRecord\Config::initialize(function($cfg) {
$cfg->set_model_directory('models');
$cfg->set_connections(array(
'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/tgregister.com/test/lib/Connection.php(239): 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.

(1-2/2)