Database connectivity issue in codeigniter


#1

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.


#2

Can you provide a screenshot of your config file for your script and a screenshot of your 000webhost.com database page?


#3

Thanks for taking the time out to help me here :slight_smile:
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?


#4

Within 000webhost.com can you provide a screenshot of the database page?

What does your panel look like when you login today?


#5

I am getting the old panel when I login.

Here’s the screenshot:


#6

How about this page sorry;


#7

Sure, here it is:


#8

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.


#9

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)


#10

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.


#11

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?


#12

Hi @fumeihana!

Please make sure your database settings are correct. Go to cPanel > Manage databases and recheck them.

Use localhost as MySQL hostname.