PHP won't connect to MySQL

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
dstefani
Forum Contributor
Posts: 140
Joined: Sat Jan 11, 2003 9:34 am
Location: Meridian Idaho, USA

PHP won't connect to MySQL

Post by dstefani »

I'm running PHP5 on Fedora Core2 with a fresh install of MySQL 4.1 max.

I womped my old mysql which was installed via an rpm, this time I installed from the binaries. When I first tried to connect with MySQL -CC it had the socket path as /var/lib/mysql/, this was the old path. When I changed it to /tmp/mysql.sock, then I could connect. I can connect from my Fedora box and I can connect from my windows box, with the control center and via a shell, but I can't do it through PHP. It is still looking for it in /var/lib/mysql/.
Here's the error:
Warning: mysql_connect() [function.mysql-connect]: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) in /usr/local/apache2/htdocs/clca/www/includes/incConnect.php on line 13
Could not connect : Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
I tried editing my php.ini on the mysql.default_socket = /tmp/mysql.sock line but with no success.

I created an /etc/my.cnf file and put the socket path in there, when I did that I could not connect from anywhere. I deleted that line and all the connections came back, except PHP of course.

I'm stumped :?:

Thanks,

- dstefani
User avatar
sakaveli
Forum Commoner
Posts: 60
Joined: Tue Apr 06, 2004 9:42 am

Post by sakaveli »

hi,

im no expert but i had the very same error last week and tried everything to solve it, but the problem in the end was ver simple to solve, it was a mis-spelling of one the lines that connect to the DB.

just re-check to make sure you have not done what i did!

sak
Post Reply