Possible Duplicate:
mysql_fetch_array() expects parameter 1 to be resource, boolean given in select
I tried to connect mysql database.but am getting the following error.
Warning:
mysql_connect(): [2002] No connection could be made because the target machine actively (trying to connect viatcp://localhost:3306) intest.phpon line 5Warning:
mysql_connect():No connection could be made because the target machine actively refused it. in test.php on line 5 Warning:mysql_close()expects parameter 1 to be resource, boolean given intest.phpon line 15
test.php:
<?php
$link = mysql_connect(localhost, dbuser, dbpass);
if (!$link) {
die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_close($link);
?>
This happened to us when running a PHP & MySQL on IIS7 in Windows Server 2008 in VirtualBox. It turns out that the Windows hosts file didn't have an IPv4 entry for localhost (127.0.0.1) so the route to MySQL on localhost was not found.
We added the following to the hosts file which resolved it:
127.0.0.1 localhost # Additional IPv4 entry
::1 localhost # Existing IPv6 localhost entry
Reference: A brief description of PHP/MySQL Localhost via IPv4 & IPv6
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With