Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

How do you specify protocol = TCP in myql_connect()?

share|improve this question

2 Answers

up vote 4 down vote accepted

By reading the manual:

Whenever you specify "localhost" or "localhost:port" as server, the MySQL client library will override this and try to connect to a local socket (named pipe on Windows). If you want to use TCP/IP, use "127.0.0.1" instead of "localhost".

http://www.php.net/manual/en/function.mysql-connect.php

share|improve this answer
Interesting. Out of curiosity, are there advantages (performance) in one versus the other? – Jason McCreary Jun 16 '11 at 1:36
@Jason Good question. I'd expect sockets to be slightly more performant, since each request doesn't need to traverse the whole TCP/IP stack. Couldn't answer this for sure though. – deceze Jun 16 '11 at 1:39
+1 Thanks for the insight and RTFM. – Jason McCreary Jun 16 '11 at 2:00

To my understanding mysql_connect() uses TCP/IP or socket. Dependable on what address you give it.

This is from PHP Manual

Note: Whenever you specify "localhost" or "localhost:port" as server, the MySQL client library will override this and try to connect to a local socket (named pipe on Windows). If you want to use TCP/IP, use "127.0.0.1" instead of "localhost". If the MySQL client library tries to connect to the wrong local socket, you should set the correct path as in your PHP configuration and leave the server field blank.

http://php.net/manual/en/function.mysql-connect.php

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.