Reputation: 24886
I am trying to set up a PHP framework on my Mac 10.6 computer, and it keeps erroring during setup due to database connectivity issues. So I put together a small php script to see if I could connect to the server myself, and it couldn't either. The operation times out.
However, I am able to login to mysql from commandline perfectly fine. It's only PHP that is having these connection issues. Does anyone have any ideas?
Here is the script.
<?php
$connection = mysql_connect("http://localhost", "root", "");
if( $connection ) {
mysql_close( $connection );
die('TRUE');
}else {
die('Could not connect: ' . mysql_error());
}
?>
EDIT: I tried removing http:// but then I get a "No such file error."
PHP Warning: mysql_connect(): [2002] No such file or directory (trying to connect via unix:///var/mysql/mysql.sock) in /Users/newuser/Downloads/t.php on line 2
PHP Warning: mysql_connect(): No such file or directory in /Users/newuser/Downloads/t.php on line 2
Could not connect: No such file or directory
Upvotes: 2
Views: 5184
Reputation: 20333
Use "127.0.0.1" it will force using TCP4 insted of sockets.
If you want to use sockets, according to this document the default socket on Mac OS X is:
/tmp/mysql.sock
Fot this to be default you should edit your php confiuration or have an .htaccess file with:
php_value mysql.default_socket "/tmp/mysql.sock"
Upvotes: 1
Reputation: 400932
You are using this :
mysql_connect("http://localhost", "root", "");
But your MySQL host is not http://localhost
: it's probably localhost
.
mysql_connect("localhost", "root", "");
EDIT after the comment : In that case, try with 127.0.0.1
(the IP address of localhost
)
[mysqld_safe]
socket = /var/run/mysqld/mysqld.sock
Then, you'll want PHP to use the same one :
mysql.default_socket
directive, about that,mysql_connect()
as a string such as ':/path/to/socket'
Upvotes: 3
Reputation: 20163
Take the "http://" out of the mysql_connect parameter. It wants a host, not an HTTP URL.
Upvotes: 1