I have a problem with the connection to database (phpmyadmin), it just because my server is in UNIX socket. I don't know how to connect to it (I'm stand on window). The code below is work fine, if my server is in TCP/IP.
My code
<?php
define('DB_SERVER', 'localhost');
define('DB_USERNAME', 'root');
define('DB_PASSWORD', 'xxxxxx');
define('DB_DATABASE', 'sample_db');
$connection = mysql_connect(DB_SERVER, DB_USERNAME, DB_PASSWORD) or die(mysql_error());
$database = mysql_select_db(DB_DATABASE, $connection) or die(mysql_error());
mysql_set_charset("utf8", $connection);
?>
Can anyone tell me how to connect to database, if the server is in UNIX socket?
Thank in advance
I'm a bit confused by your question.
Do you mean that your PHP code is running on a MSWindows machine?
If the database server and the database client (PHP) are running on different machines then they cannot communicate via UNIX filesystem sockets.
No, either your interpretation or your description of events is incorrect. If you specify 'localhost' as the target host in a libmysql client (including PHP's mysql_ extension) then the client will try to connect via the (Unix) filesystem socket. OTOH. if you specify 127.0.0.1, it will use a TCP socket.
In the former scenario, the client gets the path to the socket from ~/.my.cnf, or in the absence of that file /etc/my.cnf, or if you've compiled the client lib yourself, $PREFIX/etc/my.cnf
Just remove localhost.
Or:
In Unix you can also connect to server in same manner as
hostname
+:
+/path/to/socket
is requiredcode snippet from http://us2.php.net/function.mysql-connect
in your case
FYI, if you want to TCP socket