This blog is NOFOLLOW Free!

The magic space of the IT find what you seek or get lost


Php mysql connect ignores port for localhost

I just tried to connect with php to an other mysql server which runs on my localhost on an other port then the standard 3306. I used this syntax:

mysql_connect('localhost:3307', 'mysql_user', 'mysql_password');

But the damn php always connected to the default mysql server with port 3306.
After a lot of google searching I found the solution.

If you are using localhost as your mysql server, php always use the port 3306. It simply ignores this value.
Easy workaround, is that you use with the new port.

mysql_connect('', 'mysql_user', 'mysql_password');

Btw: If sql safemode is turned on the server paramter is ignored. Ask your hoster to change it, or to turn it off.

About kTitan

Tagged as: , Leave a comment
Comments (1) Trackbacks (0)
  1. Thanks, this just saved so much of my time.

Leave a comment

Connect with Facebook

No trackbacks yet.