0
function fafaconnect($db_host, $db_user, $db_pass, $db_name) {
	@mysql_connect($db_host, $db_user, $db_pass);
	@mysql_select_db($db_name);
}

if ($link = @mysql_connect("localhost", "admin", "pass")) {
	echo "pass-";
} else {
	echo "fail-";
}
if ($select = @mysql_select_db("zushee")) {
	echo "pass-";
} else {
	echo "fail-";
}

if ($newlink = fafaconnect("localhost", "admin", "pass", "zushee")) {
	echo "pass";
} else {
	echo "fail";
}

This returns pass-pass-fail. Any ideas?

Edited by grr: n/a

3
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by Stefano Mtangoo
0

From the PHP Documentation:

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 Runtime Configuration in your PHP configuration and leave the server field blank.

Try changing localhost to 127.0.0.1 and see if this fixes your problem. If not, try echo'ing mysql_error() instead of "fail" as this will give you more details as to why your connect call is failing.

0

I guess this have the second argument(connection) missing:

mysql_select_db($db_name)

try something like this:

$conn = mysql_connect($db_host, $db_user, $db_pass);
mysql_select_db($db_name, $conn);
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.