0
votes

The website works fine for a while but in a few days returns this error :

A PHP Error was encountered

Severity: Warning

Message: mysqli::real_connect(): (HY000/2002): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (111)

Filename: mysqli/mysqli_driver.php

Line Number: 202

Backtrace:

File: /var/www/html/application/controllers/Login.php Line: 8 Function: database

File: /var/www/html/index.php Line: 289 Function: require_once

A Database Error Occurred

Unable to connect to your database server using the provided settings.

Filename: core/CodeIgniter.php

Line Number: 500

Help will be appreciated

Thanks

Nipun

4
What's the code for line 8 in your login.php? - Fil
Is the database still running and accepting new connections when this error occurs? - aynber

4 Answers

1
votes

Three things possible. Your database has been shut down (or it has died). You have not setup database to use a unix socket when both client and server are on the same machine. Or socket is not readable and writable by web user.

0
votes

The warning is being thrown by mysqli driver. I would recommend that you use PDO driver to connect to the Database.It's simpler and a bit universal (You don't need to change Database settings once you change the DB)

0
votes

you need confirm the database config file:application/config/database.php ensure the confirm item is correct

0
votes
  1. Please check your mysql server connectivity
  2. If you run the app using your pc name i.e. sahil-pc/recruitement or http://85.215.963.104:81/recruitement you need to define it in index.php of root.

  3. please check the permission of your db socket if you are using linux you need to make it in read and write mod.

note: ip details are fake don't try it