简体   繁体   中英

Getting connection timed out with DB connection

I am trying to connect to a remote rackspace DB 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);
   } 
 ?>

And I get

Warning: mysqli::mysqli(): (HY000/2002): Connection timed out

Try this

 <?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();

       } 
     ?>

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