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?

Recommended Answers

All 2 Replies

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.

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);
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.