A Database Error Occurred
Unable to connect to your database server using the provided settings.
Filename: libraries/Session/Session.php
Line Number: 102
I am newbie for CI, went i start Db to my Website i get this error and i don't know how to reslove.
Can you resolve this error, please?
application/config/database.php
$active_group = 'default';
$query_builder = TRUE;
require_once('mainconfig.php');
$db['default'] = array(
'dsn' => '',
'hostname' => $config['mysql_host'],
'username' => $config['mysql_username'],
'password' => $config['mysql_password'],
'database' => $config['mysql_database'],
'dbdriver' => $config['mysql_driver'],
'dbprefix' => '',
'pconnect' => FALSE,
'db_debug' => TRUE,
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => $config['mysql_charset'],
'dbcollat' => $config['mysql_dbcollat'],
'swap_pre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array(),
'save_queries' => TRUE
);
application/config/mainconfig.php
defined('BASEPATH') OR exit('No direct script access allowed');
$config['mysql_host'] = 'localhost';
$config['mysql_username'] = 'xxxcc';
$config['mysql_password'] = 'xxxcc';
$config['mysql_database'] = 'xxccv';
$config['mysql_driver'] = 'mysqli';
$config['mysql_charset'] = 'utf8';
$config['mysql_dbcollat'] = 'utf8_general_ci';
$config['base_js'] = 'assets/js';
$config['base_css'] = 'assets/css';
$config['base_plugins'] = 'assets/plugins';
$config['base_images'] = 'assets/images';
$config['base_fonts'] = 'assets/font-awesome';
$config['other_base'] = 'assets/fonts';
$config['email_author'] = 'admin@localhost';
$config['limit'] = 7;
if u use codeigniter 3 then please use latest version of php. Once i got these errors but then i update my php then it works after successfully setup codeigniter on my project.
And please follow in your application/config/database.php
$active_group = 'default';
$query_builder = TRUE;
$db['default'] = array(
'dsn' => '',
'hostname' => 'localhost',
'username' => 'root',
'password' => '',
'database' => 'db_bdtimes', // your database name
'dbdriver' => 'mysqli',
'dbprefix' => '',
'pconnect' => FALSE,
'db_debug' => (ENVIRONMENT !== 'production'),
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array(),
'save_queries' => TRUE
);
Just change and it will work for sure
$db['default']['hostname'] = 'localhost';
to
$db['default']['hostname'] = '127.0.0.1';
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.