Php mysql connect

using this code

//set the conections
define(‘DB_USER’, ‘sthayden’);
define(‘DB_HOST’, ‘’);
define(‘DB_NAME’, ‘metrocss’);

//make the connection then select the database
$dbc = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);

if (!$dbc) {
die('Could not connect: ’ . mysql_error());
echo ‘Connected successfully’;


I get this error: Could not connect: Lost connection to MySQL server during query

if I take out the mysql_error() I get this error message: Can’t connect to local MySQL server through socket ‘/tmp/mysql.sock’ (2)

because of " PHP’s allow_url_fopen NOW Disabled (Action Required)" I’ve had to move my project for graduation. I’d use the CURL sugested but don’t completly understand it can’t seem to get it to work from other’s examples.

any help would be amazing

If you’re trying to access your database from an other server (your school’s) have you set up your DB to allow connections from the new server’s IP as sigguested in the other thread?


in the user account I have it accepting conections from

I’m not sure as I’ve never done this my self, but you might try allowing an IP or range of IPs instead - if you can determin that for your school’s server.

Possibly the DH server logs show the failed connection attempts, and you could get the IP from there if you don’t know it?

Hope this is at least somewhat helpful… if not sorry.


It worked for me when I did the actual IP and not the domain.