Unable to Connect to MySQL Host (sql305.infinityfree.com or sql305.epizy.com)

Error Message: When attempting to connect via my PHP code, I get the error:
Error establishing a database connection.

DNS Issue: When I use nslookup for both links received the following response:

Server: UnKnown
Address: 192.168.99.2

When i tried with epizy provider:
Addresses: 64:ff9b::c0a8:c3
192.168.0.195

However, still unable to connect using these addresses or hostnames.

I verified the database credentials (host, username, password, database name). Tested the database connection using a PHP script and MySQL clients. Checked DNS resolution and network configuration. Switched to Google’s DNS (8.8.8.8/8.8.4.4) on my local machine.

Could you confirm if the database host sql305.infinityfree… or its alias sql305.epizy… is operational? Additionally, are there any known issues with accessing this MySQL server from certain regions or networks?

Hi and welcome to the forum! Did you read this article already?

And you can’t access MySQL from your local machine, as the IP you’ll get from the lookup might also be a local IP which will not resolve on your side.

7 Likes

Make sure you are using the right database name and username

I am pretty sure i am using right credentials. I actually was able to connect and send data to my database through PHP script few hours before I encountered the issue. Then checked if the credentials have been transferred to epizy domain, found out it actually happened when I found out the IP of the through command promt. with epizy structure instead (not with what the cpanel shows- inf0 structure). I applied the pass (not the client one- the host pass); and db and host name that matches the domain… And its still not working out.

You cannot connect to a free hosting MySQL database from outside your hosting account.

I am am connecting the free hosting database through PHP scripts withing my hosting ac.

Where is your PHP script hosted? Is it on the same hosting account within an htdocs folder?

Can you share the contents of the script that related to database connection? Hide your password.

5 Likes
<?php
// Display errors
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

var_dump($_POST['contentData']); // Check the contentData
var_dump($_FILES); // Check the uploaded files

// Database connection
$host = 'sql305.epizy.com'; //infinityfree
$db = 'epiz_37717046_website_data'; //inf0
$user = 'epiz_37717046'; //inf0
$pass = '';


try {
    $pdo = new PDO("mysql:host=$host;dbname=$db", $user, $pass);
    $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) {
    die("Database connection failed: " . $e->getMessage());
}

    $title = $_POST['title'] ?? null;
    $author = $_POST['author'] ?? null;
    $created_at = $_POST['created-at'] ?? null; // Form- 'created-at'
    $tags = $_POST['tags'] ?? null; // Tags field

    if (!$title || !$author || !$created_at) {
        die("Missing required fields.");
    }

    try {
        $stmt = $pdo->prepare(
            "INSERT INTO `blog_posts` (`title`, `author`, `created_at`) VALUES (?, ?, ?)"
        );
        $stmt->execute([$title, $author, $created_at]);

        $post_id = $pdo->lastInsertId();
    } catch (PDOException $e) {
        die("Error inserting post: " . $e->getMessage());
    }

    // Handle tags
    if ($tags) {
        $tags = explode(',', $tags); //  tags are comma-separated
        foreach ($tags as $tag) {
            $tag = trim($tag);

            // Check if the tag exists
            $stmt = $pdo->prepare("SELECT id FROM tags WHERE name = ?");
            $stmt->execute([$tag]);
            $tagId = $stmt->fetchColumn();

            if (!$tagId) {
                $stmt = $pdo->prepare("INSERT INTO tags (name, slug) VALUES (?, ?)");
                $slug = strtolower(str_replace(' ', '-', $tag)); // Create a slug from the tag name
                $stmt->execute([$tag, $slug]);
                $tagId = $pdo->lastInsertId(); // Get the new tag's ID
            }

            $stmt = $pdo->prepare("INSERT INTO post_tags (post_id, tag_id) VALUES (?, ?)");
            $stmt->execute([$post_id, $tagId]);
        }
    }


//upload image

    $image_url = null; // Default image URL to null
    if (isset($_FILES['image']) && $_FILES['image']['error'] === UPLOAD_ERR_OK) {
        $imageTmpPath = $_FILES['image']['tmp_name'];
        $imageName = uniqid() . '-' . basename($_FILES['image']['name']); // unique names
        $uploadDir = 'uploads/images/';

        if (!file_exists($uploadDir)) {
            mkdir($uploadDir, 0777, true);
        }

        $uploadPath = $uploadDir . $imageName;

        if (move_uploaded_file($imageTmpPath, $uploadPath)) {
            $image_url = $uploadPath;
        } else {
            echo json_encode([
                'success' => false,
                'message' => 'Failed to move uploaded file'
            ]);
            exit;
        }
    }

    if (isset($_POST['contentData'])) {
        $contentData = json_decode($_POST['contentData'], true);

        // Prepare to store each piece of content
        foreach ($contentData as $content) {
            $type = $content['type'];
            $order = $content['order'];
            $text_content = $content['content'] ?? null;
            $alt = $content['alt'] ?? null;
            $figcaption = $content['figcaption'] ?? null;

            try {
                if ($type === 'text') {
                    $stmt = $pdo->prepare(
                        "INSERT INTO `post_content` (`post_id`, `content_type`, `content`, `order`) 
                         VALUES (?, 'text', ?, ?)"
                    );
                    $stmt->execute([$post_id, $text_content, $order]);
                } elseif ($type === 'image' && $image_url !== null) {
                    $stmt = $pdo->prepare(
                        "INSERT INTO `post_content` (`post_id`, `content_type`, `image_url`, `alt`, `figcaption`, `order`) 
                         VALUES (?, 'image', ?, ?, ?, ?)"
                    );
                    $stmt->execute([$post_id, $image_url, $alt, $figcaption, $order]);
                }
            } catch (PDOException $e) {
                die(json_encode([
                    'success' => false,
                    'message' => 'Error inserting content: ' . $e->getMessage()
                ]));
            }
        }
    }

    // Success response
    echo json_encode(['success' => true, 'message' => 'Post saved successfully']);
} else {
    die("Invalid request method.");
}
?>

Password is empty

4 Likes