0

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

2
  • What's the code for line 8 in your login.php? Commented Aug 9, 2016 at 16:34
  • Is the database still running and accepting new connections when this error occurs? Commented Aug 9, 2016 at 16:39

4 Answers 4

1

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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)

Comments

0

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

Comments

0
  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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.