简体   繁体   中英

repost No connection could be made because the target machine actively refused it. in C:\xampp\htdocs\frix\checkcon.php on line 2

when i run it on the browser given the url localhost/foldername/checkcon.php. it always post the error

here is my code

<?php
$con=mysqli_connect("192.168.1.130","root","color","inventory1");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

$result = mysqli_query($con,"SELECT * FROM tblemployee");

while($row = mysqli_fetch_array($result))
{
echo $row['Employee_ID'] . " " . $row['Employee_Name'];
echo "<br>";
}

mysqli_close($con);
?>

Your MySQL server probably allows connections only from localhost. So if your database is on the same machine as that script is, change the ip from mysqli_connect to 127.0.0.1, or reconfigure your MySQL to allow connections from outside of localhost.

您确定要输入正确的凭据吗?尤其是

mysqli_connect("myhost","myuser","mypassw","mybd")

This issue is most probably caused by Firewall . Try disabling it and try again.
If this doesn't work... Try replacing your IP Address with localhost or 127.0.0.1 (loopback address) on your mysqli connect statement.

$con=mysqli_connect("localhost","root","color","inventory1");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM