views:

90

answers:

3

What I mean is when:

mysql_connect('localhost', 'root', 'root');

I provide 'localhost' as the first argument without ever stopping to think what purpose it serves. I guess the opposite would be remote host, but when would you actually use it?

Hope it is not a too stupid question, but I really dont know why its there...

+4  A: 

localhost is a hostname that refers to the local machine.

Therefore, you pass that to connect to a server running on the local machine.

If you want to connect to a MySQL server running on a different machine, you would pass that machine's domain name or IP address instead of localhost .

SLaks
That is simple enough, thank you, very clear answer!
Trufa
+1  A: 

It depends where the SQL server is living. In an application architecture you could potentially have UI, Services, and SQL living on separate boxes. In this scenario you'd point mysql_connect() to the appropriate machine.

Alex
+1  A: 

localhost is simply an alias for the computer that you are running the script on. By connecting to localhost, you are connecting to a server on the same computer.

Replacing 'localhost' with an IP or host name allows you to connect to a different computer.

thekidder