This blog is NOFOLLOW Free!

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

11Mar/10Off

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 127.0.0.1 with the new port.

mysql_connect('127.0.0.1:3307', '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.

Fatal error: Call to undefined function the_flattr_permalink() in /srv/www/webs/aschneider/magicspace_eu/htdocs/wp-content/themes/lightword-custom/single.php on line 23 Call Stack: 0.0001 235176 1. {main}() /srv/www/webs/aschneider/magicspace_eu/htdocs/index.php:0 0.0002 238136 2. require('/srv/www/webs/aschneider/magicspace_eu/htdocs/wp-blog-header.php') /srv/www/webs/aschneider/magicspace_eu/htdocs/index.php:17 0.7928 54709312 3. require_once('/srv/www/webs/aschneider/magicspace_eu/htdocs/wp-includes/template-loader.php') /srv/www/webs/aschneider/magicspace_eu/htdocs/wp-blog-header.php:19 0.8004 55137008 4. include('/srv/www/webs/aschneider/magicspace_eu/htdocs/wp-content/themes/lightword-custom/single.php') /srv/www/webs/aschneider/magicspace_eu/htdocs/wp-includes/template-loader.php:74