tags:

views:

102

answers:

3

Hey!

Does anyone know how php requests data from mysql?

If I have mysql in the same machine as php, does it open a tcp connection to the localhost on port 3306 or does it have some other way of getting the data?

Is it the same in linux and windows?

Thanks

A: 

PHP opens a connection to port 3306 is the server via TCP to allow data communication. Hence, you can specify which port to connect to in mysql(i)_connect etc, and why, you need to have firewall rules for mysql.

It is the same in Windows as Linux

So yes, TCP :)

EDIT: Revision, In linux, php looks to connect to mysql via /tmp/mysql.sock the tmp directory needs to have correct permissions.

Shamil
on unix it tries to not use TCP !
AlberT
it does on mine... it's always complaining about not finding /tmp/mysql.sock.... and yes, I've had server management on it, but doesn't work.
Shamil
@ct2k7: It sounds like your MySQL client is looking for the socket file in a different place than the MySQL server has created it. This is not an unusual "disconnect." Check your php.ini's idea of the socket file location versus your my.cnf's configuration.
Bill Karwin
myself and server administration have looked for it to no avail, even checked permissions on everything. However, it might be due to that fact that one of our custom software is incompatible or causing the problem, we're probing things at the moment.
Shamil
+2  A: 

Usually PHP opens up a local pipe found at /tmp/mysql.sock to connect to a local version of the server, unless you use an IP address in your connection string.

razzed
not on Windows it doesn't!
Shamil
Yes, except on Windows where it uses an IP address regardless, I believe. (Been a while since I used MySQL on Windows)
razzed
+7  A: 

if available it uses a unix socket, otherwise localhost.

Note that even if you specify localhost in the connection string it will try to use the faster "unix socket" if available

AlberT