发生数据库错误
无法使用提供的设置连接到数据库服务器。
文件名:libraries / Session / Session.php
行号:102
我是CI的新手,我开始Db到我的网站我收到此错误,我不知道如何重新开始。
请问你能解决这个错误吗?
应用/配置/ 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
);
应用/配置/ 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;
答案 0 :(得分:0)
如果您使用codeigniter 3,请使用最新版本的PHP。一旦我得到这些错误,但后来我更新我的PHP然后它成功设置我的项目上的codeigniter后工作。
请关注您的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
);
答案 1 :(得分:0)
只需改变,它肯定会起作用
$ db ['默认'] ['主机名'] =' localhost';
到
$ db ['默认'] ['主机名'] =' 127.0.0.1';