Unable to connecte to the database |
Hello everyone,
My website won't show on live server because it can't connect to the database. Here is the database configuration: $active_group = 'default'; $query_builder = TRUE; $db['default'] = array( 'dsn' => '', 'hostname' => 'localhost', 'username' => 'user_root', 'password' => '*****', 'database' => 'mydb', 'dbdriver' => 'mysqli', 'dbprefix' => '', 'pconnect' => FALSE, 'db_debug' => TRUE, 'cache_on' => FALSE, 'cachedir' => '', 'char_set' => 'utf8', 'dbcollat' => 'utf8_general_ci', 'swap_pre' => '', 'encrypt' => FALSE, 'compress' => FALSE, 'stricton' => FALSE, 'failover' => array(), 'save_queries' => TRUE ); The error messages? Here they are: 1. 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' (2) Filename: mysqli/mysqli_driver.php Line Number: 135 Backtrace: File: /usr/local/pem/vhosts/109098/webspace/httpdocs/mydomain.com/sthes/application/controllers/Home.php Line: 20 Function: __construct File: /usr/local/pem/vhosts/109098/webspace/httpdocs/mydomain.com/index.php Line: 294 Function: require_once 2. A PHP Error was encountered Severity: Warning Message: Cannot modify header information - headers already sent by (output started at /usr/local/pem/vhosts/109098/webspace/httpdocs/mydomain.com/sthes/system/core/Exceptions.php:272) Filename: core/Common.php Line Number: 564 Backtrace: File: /usr/local/pem/vhosts/109098/webspace/httpdocs/mydomain.com/sthes/application/controllers/Home.php Line: 20 Function: __construct File: /usr/local/pem/vhosts/109098/webspace/httpdocs/mydomain.com/index.php Line: 294 Function: require_once 3. A Database Error Occurred Unable to connect to your database server using the provided settings. Filename: controllers/Home.php Line Number: 20
checklist to follow
1) connection details are correct 2) mysql server is running fine 3) check with command line or desktop client with same credential whether connecting fine. If all above correct, you are done.. you will face no issue. ![]()
MySQLi Test Script:
PHP Code: <?php What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
I wonder why the client tries to connect to the MySQL server through a socket. Is this intended?
(06-09-2016, 05:28 AM)ivantcholakov Wrote: I wonder why the client tries to connect to the MySQL server through a socket. Is this intended? I don't know exactly how the issue of connecting through the socket came about. Using CI framework I simply put the data in the config/database.php file.How can I connect to the db without the socket? Thanks ivantcholakov (06-09-2016, 03:16 AM)InsiteFX Wrote: MySQLi Test Script: Thanks you InsiteFX for your suggestion I simply verified repeatedly that the data I used was correct. Am going to test this code you've given
I don't see anything wrong in your settings. Use the suggested test by InsiteFX to see whether you can connect to the MySQL server at all, without using CodeIgniter.
I have tried the code, replacing the content of config/database.php file. As expected it didn't work since CI framework expects an array from this file then it will do the connection itself.
No just run the code from straight php
What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
(06-09-2016, 10:42 AM)InsiteFX Wrote: No just run the code from straight php Hello everyone Thanks so much for the prompt guide you are giving me. I have used the suggested code of InsiteFx in my index.php (in a manner that eliminates CI) and still could not connect to the DB. The error msg is: "Failed to Connect to MySQL: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)" Thanks in advance for further suggestion. |
Welcome Guest, Not a member yet? Register Sign In |