I am having trouble connecting to my MySQL databases using PHP. To begin, when I first try to establish connection to the database, the connection is remarkably slow. Then anytime I try to make a query (in this case, I’m trying to Insert into one of my tables), I get the Connection failed: Connection Timed Out.
<?php
if(isset($_POST["submit"])){
$check = getimagesize($_FILES["image"]["tmp_name"]);
if($check !== false){
$image = $_FILES['image']['tmp_name'];
$imgContent = addslashes(file_get_contents($image));
$dbHost = 'sql***.epizy.com';
$dbUsername = 'epiz_user';
$dbPassword = 'password';
$dbName = 'epiz_user_table';
$db = new mysqli($dbHost, $dbUsername, $dbPassword, $dbName);
if($db->connect_error){
die("Connection failed: " . $db->connect_error);
}
$dataTime = date("Y-m-d H:i:s");
$insert = $db->query("INSERT into testing (image, created) VALUES ('$imgContent', '$dataTime')");
if($insert){
echo "File uploaded successfully.";
}else{
echo "File upload failed, please try again.";
}
}else{
echo "Please select an image file to upload.";
}
}
?>