Reputation: 13
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
Upvotes: 1
Views: 283
Reputation: 1
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
Upvotes: 0
Reputation: 1
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’);
Upvotes: 0