MySQL: Connection timed out

Username (e.g. epiz_XXX) or Website URL

username: epiz_27699881

Error Message

Failed to connect to MySQL: Connection timed out

Other Information

Can’t connect to db via php
i think sql311.epizy.com is offline

$db_host = “sql311.epizy.com”;
$db_user = “epiz_27699881”;

$con=mysqli_connect($db_host,$db_user,$db_pass,$db_name);

Hmmmm…
Make sure your code is correct

Also, I would suggest you to use PDO instead. Your code is very vulnerable to SQL injection attacks. Even if your website only has a few visitors, it’s always cosidered as the best practice to take security measures

Here’s some code for you in PDO:

<?php 
$servername = '<YOUR_SERVER_NAME>'; // In this case: sql311.epizy.com
$dbname = '<YOUR_DATABASE_NAME>'; // Make sure your database is correct 
$username = '<YOUR_USERNAME>'; // In this case: (epiz_27699881)
$password = '<YOUR_PASSWORD>'; // MAKE SURE YOUR PASSWORD IS CORRECT!!! If you are using a $ in your password, you'll need to escape it (\$)
try {
    $dbh = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
    $sql = "SELECT * FROM someplace WHERE somefield=".$_SESSION['id'];
    $users = $dbh->query($sql);
    echo '<table class="table">
    <tr>
    <td>Name</td>
    <td>Quantity</td>
    </tr>';
    foreach ($users as $row) {
        echo "<tr><td>".$row['id']."</td><td>".$row['name']."</td></tr>";
    }
    $dbh = null;
}
catch (PDOexception $e) {
    echo "Error is: " . $e-> etmessage();
}
?>
2 Likes

Code is correct but the sql311.epizy.com server is offline

Can you please provide a URL on your site where you have this issue so I can check it?

1 Like

nevermind, i fix my problem
thread to close