My website was working fine for some time until it suddenly stopped connecting to the database. It gives the following error:
Message: mysqli::real_connect() [mysqli.real-connect]: (HY000/2013): Lost connection to MySQL server at ‘reading initial communication packet’, system error: 113
On reading about similar issues on the forums, I found out that this could be due to server maintenance. However it has been more than 3 days and the issue still persists. I would like to make clear that the site was working perfectly and I did not make any changes. Any help on this issue would be appreciated.
Website link:
Thanks in advance.
shash95:
: mysqli::real_connect()
Can you provide a screenshot of your config file for your script and a screenshot of your 000webhost.com database page?
Thanks for taking the time out to help me here
This is the database.php file in the config folder.
I’m not sure if I correctly understand what you mean by the database page. Do you want me to share a screenshot of the php myadmin area?
Within 000webhost.com can you provide a screenshot of the database page?
What does your panel look like when you login today?
I am getting the old panel when I login.
Here’s the screenshot:
How about this page sorry;
Could you try this tutorial just paste the code into .php file and edit the values to what your site uses above
host: mysql8.000webhost.com
username: a5248758_example
password:
And load the .php file into your hosting and run it and you’ll see if it connected successfully or not please?
Ignore anything about the new panel if you aren’t on it - the code is all you need.
Introduction
You can create databases on 000webhost.com and PHP can be used to connect to those databases. This tutorial explains three different methods how that could be achieved. Most of the websites need to have at least one database and if you are developing a website from the beginning you will have to connect it to a database manually, here you can find how that could be done step by step.
What you'll need
Before you begin this guide you'll need the following:
Understanding of PHP …
I tried the mysqli version of the code. Unfortunately it gives the same error.
Can’t connect to MySQL server on ‘mysql8.000webhost.com ’ (113)
1 Like
Can you run all three snippets in a test.php file to see which one connects successfully?
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";
?>
Else hit Infinity, then message and send over your 000webhost.com login details and I’ll investigate further.
This is my first time creating and host website bymyself. but its keep mentioning this error.
I didn’t do anything to mysqli_driver.php
I did the configuration in config>config.php and database.php
Please help me with this.What did i do incorrectly?
teodor
June 2, 2017, 9:06pm
#12
Hi @fumeihana !
Please make sure your database settings are correct. Go to cPanel > Manage databases and recheck them.
Use localhost
as MySQL hostname.