1
votes

Not able to connect MySQL... detail given bellow.

A PHP Error was encountered

Severity: Warning

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

Filename: mysqli/mysqli_driver.php

Line Number: 202

Backtrace:

File: /var/www/html/application/controllers/Account.php Line: 7 Function: __construct

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

2
Your MySQL server isn't running, has crashed, or doesn't create a sock file where you think it does.tadman
sock file is exist on path ...but I am not able to start MySQL service.... when I going to start services its giving above errorkrishna
Existing and being operational are two different things. Are you sure your process has permission to access it? Can you connect over IP instead?tadman
No, I am not sure. If there is any way to check this ? And how I solved this Error ?krishna

2 Answers

0
votes

First you need to download xampp and ensure that my sql services on or off .if it is on then you are write function mysqli_connect(‘localhost’,’username’,’password’,’database’);

0
votes

I guess you have a xampp installed in your system and SQL service was enabled. If yes, then create one database file in your application/config folder. Filename is database.php Here you need to give a default db driver variable, likewise

$db['default'] = array(
    'dsn'   => '',
    'hostname' => 'localhost',
    'username' => 'your-db-username',
    'password' => 'your-db-password',
    'database' => 'your-db-name',
    'dbdriver' => 'mysqli',
    'dbprefix' => '',
    'pconnect' => FALSE,
    'db_debug' => (ENVIRONMENT !== 'production'),
    'cache_on' => FALSE,
    'cachedir' => '',
    'char_set' => 'utf8mb4',
    'dbcollat' => 'utf8_general_ci',
    'swap_pre' => '',
    'encrypt' => FALSE,
    'compress' => FALSE,
    'stricton' => FALSE,
    'failover' => array(),
    'save_queries' => TRUE
);

Next, you need to load this database.php config file in autoload.php (in the same directory).

$autoload['libraries'] = array('database');

Now, you have connected a database with your Codeigniter project.

Reference : https://www.codeigniter.com/userguide3/database/configuration.html