views:

52

answers:

2

Hello all

On my Unix web server, I have two MySQL database servers running. One on port 3306, and another on 3307. I wanted to specify the port number of database to connect in /config/database.php of codeigniter.

I tried this....

$database['hostname'] = "localhost:3307";

This did not work. The webapp connected to database on port 3306.

Then I tried this....

$database['hostname'] = "127.0.0.1:3307";

This worked. The webapp got connected to the database on port 3307.

I don't understand why? Can somebody please throw some light on this. I think this is not a codeigniter specific issue inspite of the title.

Regards

+1  A: 

Hi ShiVik,

There is a port index in the config. Try this:

$database['port'] = 3307;

More info here (at the bottom of the page):

http://codeigniter.com/user_guide/database/configuration.html

treeface
@treeface - `port - The database port number. Currently only used with the Postgres driver.` I have stated in my question that I am using MySQL. Besides I know how to set the port number, I want to know why the localhost doesn't work, while 127.0.0.1 does when I use `hostname:port`.
ShiVik
Oh, well...sorry I can't help you further.
treeface
+2  A: 

I'd guess localhost is valid for IPv6 also, but 127.0.0.1 is undeniably an IPv4 address, so therefore it might throw some spanners into your machinery.

I've run into that a few times. (FireFox is/was notorious for being slow on localhost:8000 but fast on 127.0.0.1:8000 when developing with Django)

Marcus Lindblom