Warning: mysql_connect() [function.mysql-connect]: No such file or directory

I spent an age trying to work out why I couldn’t post a simple e-mail address to a PHP database. Everytime I tried to test submitting the form using my local server I got the following message:

Warning: mysql_connect() [function.mysql-connect]: No such file or directory

I was using the following connection string:

mysql_connect ("localhost",  "root", "xxxx", "my_fdb") or die ('Error: ' .mysql_error());

It turns out that when I changed “localhost” to the actual ip address and port of my local mySQL database, the error disapeared:

mysql_connect ("127.0.0.1:3306",  "root", "xxxx", "my_fdb") or die ('Error: ' .mysql_error());

Now if I was on a windows machine I would have known where to go to edit my locahosts file, but on a mac I haven’t the first clue and right now I don’t care, I’m just pleased that I’m now able to write to and read from my local database.

Advertisements

6 thoughts on “Warning: mysql_connect() [function.mysql-connect]: No such file or directory

Please leave a comment - any questions or feedback welcome.

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s