Mysql connect a6937125

Good morning everyone,

I have not changed the .php file that i use to access my databse in 2 years, and all of a sudden I am getting this message:

Warning: mysql_connect() [function.mysql-connect]: Lost connection to MySQL server at ‘reading initial communication packet’, system error: 113 in /home/a6937125/public_html/inc_connect.php on line 3

I am assuming this is something on 000webhost’s end, but I can’t find any info on it. Any information would be appreciated.

Thanks
Jeff

What is your domain name??

Can you provide a screenshot of your 000webhost.com control panel database page?

Also if you could try the code in the tutorials in a blank .php file that’d help too?

“MySQL database page” screenshot

Use the details provided on that page to fill in the values below in the script and upload to your site like test.php and visit the page and find out what connection was successful.

Method 1 — Connecting to the database using PDO (recommended)

<?php
$servername = "localhost";
$username = "username";
$password = "password";
$database = "database";

try {
    $conn = new PDO("mysql:host=$servername;dbname=$database", $username, $password);
    // set the PDO error mode to exception
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    echo "Connected successfully"; 
    } catch(PDOException $e) {    
    echo "Connection failed: " . $e->getMessage();
    }
?>

Method 2 — Connecting to the database using mysqli (Object-Oriented)

<?php

$servername = "localhost";
$username = "username";
$password = "password";
$database = "database";

// Create connection
$conn = new mysqli($servername, $username, $password, $database);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
?>

Method 3 — Connecting to the database using mysqli_connect (Procedural)

<?php

$servername = "localhost";
$username = "username";
$password = "password";
$database = "database";

// Create connection
$conn = mysqli_connect($servername, $username, $password, $database);

// Check connection
if (!$conn) {
    die("Connection failed: " . mysqli_connect_error());
}

echo "Connected successfully";
?>

I have tried all three methods described about, using both localhost and mysql8.000webhost.com as my servername and get different errors each time

What difference do the errors show?
localhost
mysql8

Using the PDO method with

mysql8: Connection failed: SQLSTATE[HY000] [2003] Can’t connect to MySQL server on ‘mysql8.000webhost.com’ (113)

localhost: Connection failed: SQLSTATE[28000] [1045] Access denied for user ‘a6937125_jaj78’@‘localhost’ (using password: YES)

Can you change your database password to something else within 000webhost.com and then retry PDO with localhost?

I’m still getting this error:
Connection failed: SQLSTATE[28000] [1045] Access denied for user ‘a6937125_jaj78’@‘localhost’ (using password: YES)

fyi, it still shows host name as mysql8 on my mysql page…

1 Like

Yeah I know I just thought it would be worth a try - I’ll try some more things and get back to you sorry.

Sounds good. Thank you for looking in to this. Im at a loss. This was working exactly as is up until about 8pm est last night.

Can you create a new database like test and password 123456 for example and attach the details here?

I created a new test db, here are the specifics…

<?php $servername = "localhost"; $username = "a6937125_test1"; $password = "test123"; $database = "a6937125_test1"; try { $conn = new PDO("mysql:host=$servername;dbname=$database", $username, $password); // set the PDO error mode to exception $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); echo "Connected successfully"; } catch(PDOException $e) { echo "Connection failed: " . $e->getMessage(); } ?>

and the results:

Connection failed: SQLSTATE[28000] [1045] Access denied for user ‘a6937125_test1’@‘localhost’ (using password: YES)

and when i change the host to mysql8 it gives me this error:

Connection failed: SQLSTATE[HY000] [2003] Can’t connect to MySQL server on ‘mysql8.000webhost.com’ (113)

Hmm I see this now.
I’ve tested via the old control panel on my hosting which gives mysql13, so it could be a temporary problem with mysql8 so I’ve raised this with an administrator. I’ll update this when I’ve found more out.

Great, thanks again for your help.