使用数据库连接获得连接超时

时间:2017-04-26 13:48:34

标签: php mysql database mysqli

我正在尝试连接到远程机架空间数据库 PHP:

<?php
  $servername = "XX.XX.XX.XX";
   $username = "username";
   $password = "password";
   $dbname = "table";
    // Create connection
       $conn = new mysqli($servername, $username, $password, $dbname);
     // Check connection
       if ($conn->connect_error) {
      die("Connection failed: " . $conn->connect_error);
   } 
 ?>

我收到警告:mysqli :: mysqli():( HY000 / 2002):连接超时 任何建议

1 个答案:

答案 0 :(得分:0)

试试这个

 <?php
      $servername = "XX.XX.XX.XX";
       $username = "username";
       $password = "password";
       $dbname = "table";
        // Create connection
           $conn = mysqli_connect($servername, $username, $password, $dbname);
         // Check connection
           if (mysqli_connect_errno()) {
         echo "Failed to connect to MySQL: " . mysqli_connect_error();die();

       } 
     ?>