PHP / MYSQLI - 警告:mysqli_connect():( HY000 / 2002):连接超时

时间:2017-03-05 17:21:15

标签: php mysql mysqli

我已经从另一个有效且仅更改了查询的脚本中复制了这个脚本。但是当使用它时,我得到一个错误,连接超时。用户,密码,数据库和主机是对的。

有什么可以对此负责? 请注意,其他脚本没有连接错误。

<?php 

$name = $_POST["name"];


$user = "....";
$password = "....";
$host = "...";
$db_name = "....";



$con = mysqli_connect($host, $user, $password, $db_name);
$sql = "INSERT INTO `wg_groups` (`name`) 
VALUES ('".$name."');";

if (mysqli_connect_errno())
{echo "Failed to connect to MySQL: " . mysqli_connect_error();
    //you need to exit the script, if there is an error
    exit();}

if(mysqli_query($con, $sql))
{
    echo "Data insertion success ...";
}
else
{
    echo "Error while insertion";
}
mysqli_close($con);

?>

0 个答案:

没有答案