As far as I understand, mysql_connect() uses TCP / IP or a socket. Itβs reliable what address you give him.
This is from the PHP manual.
Note: Whenever you specify "localhost" or "localhost: port" as the server, the MySQL client library will override this and try to connect to the local socket (named pipe in Windows). If you want to use TCP / IP, use "127.0.0.1" instead of "localhost". If the MySQL client library is trying to connect to the wrong local socket, you must set the correct path, as in your PHP configuration, and leave the server field blank.
http://php.net/manual/en/function.mysql-connect.php
source share