本文介绍了Codeigniter:无法连接到数据库,服务器错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个codeigniter web应用程序,它在灯工作,但不工作在wamp。当我尝试访问该网站时会出现以下错误
无法使用提供的设置连接到数据库服务器。
文件名:E:\wamp\www\CI\system\database\DB_driver.php
行号:114
我在应用程序中使用了mysql和sqlite。
php
$ active_group ='default';
$ active_record = TRUE;
$ db ['login'] ['hostname'] ='localhost';
$ db ['login'] ['username'] ='root';
$ db ['login'] ['password'] ='';
$ db ['login'] ['database'] ='login';
$ db ['login'] ['dbdriver'] ='mysql';
$ db ['login'] ['dbprefix'] ='';
$ db ['login'] ['pconnect'] = TRUE;
$ db ['login'] ['db_debug'] = TRUE;
$ db ['login'] ['cache_on'] = FALSE;
$ db ['login'] ['cachedir'] ='';
$ db ['login'] ['char_set'] ='utf8';
$ db ['login'] ['dbcollat'] ='utf8_general_ci';
$ db ['login'] ['swap_pre'] ='';
$ db ['login'] ['autoinit'] = TRUE;
$ db ['login'] ['stricton'] = FALSE;
$ db ['pm'] ['hostname'] ='localhost';
$ db ['pm'] ['username'] ='root';
$ db ['pm'] ['password'] ='';
$ db ['pm'] ['database'] ='password_manager';
$ db ['pm'] ['dbdriver'] ='mysql';
$ db ['pm'] ['dbprefix'] ='';
$ db ['pm'] ['pconnect'] = TRUE;
$ db ['pm'] ['db_debug'] = TRUE;
$ db ['pm'] ['cache_on'] = FALSE;
$ db ['pm'] ['cachedir'] ='';
$ db ['pm'] ['char_set'] ='utf8';
$ db ['pm'] ['dbcollat'] ='utf8_general_ci'
$ db ['pm'] ['swap_pre'] ='';
$ db ['pm'] ['autoinit'] = TRUE;
$ db ['pm'] ['stricton'] = FALSE;
$ db ['user'] ['hostname'] ='localhost';
$ db ['user'] ['username'] ='root';
$ db ['user'] ['password'] ='';
$ db ['user'] ['database'] ='user_info';
$ db ['user'] ['dbdriver'] ='mysql';
$ db ['user'] ['dbprefix'] ='';
$ db ['user'] ['pconnect'] = TRUE;
$ db ['user'] ['db_debug'] = TRUE;
$ db ['user'] ['cache_on'] = FALSE;
$ db ['user'] ['cachedir'] ='';
$ db ['user'] ['char_set'] ='utf8';
$ db ['user'] ['dbcollat'] ='utf8_general_ci';
$ db ['user'] ['swap_pre'] ='';
$ db ['user'] ['autoinit'] = TRUE;
$ db ['user'] ['stricton'] = FALSE;
$ db ['transaction'] ['hostname'] ='localhost';
$ db ['transaction'] ['username'] ='root';
$ db ['transaction'] ['password'] ='';
$ db ['transaction'] ['database'] ='user_transactions';
$ db ['transaction'] ['dbdriver'] ='mysql';
$ db ['transaction'] ['dbprefix'] ='';
$ db ['transaction'] ['pconnect'] = TRUE;
$ db ['transaction'] ['db_debug'] = TRUE;
$ db ['transaction'] ['cache_on'] = FALSE;
$ db ['transaction'] ['cachedir'] ='';
$ db ['transaction'] ['char_set'] ='utf8';
$ db ['transaction'] ['dbcollat'] ='utf8_general_ci';
$ db ['transaction'] ['swap_pre'] ='';
$ db ['transaction'] ['autoinit'] = TRUE;
$ db ['transaction'] ['stricton'] = FALSE;
SQLITE PDO
class CI_Appdb {
var $ conDb;
public function __construct($ userId = NULL){
$ this-> db($ userId ['user_id']);
}
public function close(){
$ this-> conDb-> close();
}
私人函数db($ userId){
if($ userId){
$ this-> conDb = new PDO(sqlite:。 BASEPATH。sqlitedb /。$ userId。/app_data.db);
}
}
public function query($ query){
return $ this-> conDb-> query($ query);
}
}
解决方案您已定义 $ active_group ='default'
,但您的数据库设置中没有默认组。
I have a codeigniter web application which is working in lamp but not working in wamp. When I try to access the site it gives the following error
Unable to connect to your database server using the provided settings.
Filename: E:\wamp\www\CI\system\database\DB_driver.php
Line Number: 114
I have used mysql and sqlite in my application.
Database.php
$active_group = 'default';
$active_record = TRUE;
$db['login']['hostname'] = 'localhost';
$db['login']['username'] = 'root';
$db['login']['password'] = '';
$db['login']['database'] = 'login';
$db['login']['dbdriver'] = 'mysql';
$db['login']['dbprefix'] = '';
$db['login']['pconnect'] = TRUE;
$db['login']['db_debug'] = TRUE;
$db['login']['cache_on'] = FALSE;
$db['login']['cachedir'] = '';
$db['login']['char_set'] = 'utf8';
$db['login']['dbcollat'] = 'utf8_general_ci';
$db['login']['swap_pre'] = '';
$db['login']['autoinit'] = TRUE;
$db['login']['stricton'] = FALSE;
$db['pm']['hostname'] = 'localhost';
$db['pm']['username'] = 'root';
$db['pm']['password'] = '';
$db['pm']['database'] = 'password_manager';
$db['pm']['dbdriver'] = 'mysql';
$db['pm']['dbprefix'] = '';
$db['pm']['pconnect'] = TRUE;
$db['pm']['db_debug'] = TRUE;
$db['pm']['cache_on'] = FALSE;
$db['pm']['cachedir'] = '';
$db['pm']['char_set'] = 'utf8';
$db['pm']['dbcollat'] = 'utf8_general_ci';
$db['pm']['swap_pre'] = '';
$db['pm']['autoinit'] = TRUE;
$db['pm']['stricton'] = FALSE;
$db['user']['hostname'] = 'localhost';
$db['user']['username'] = 'root';
$db['user']['password'] = '';
$db['user']['database'] = 'user_info';
$db['user']['dbdriver'] = 'mysql';
$db['user']['dbprefix'] = '';
$db['user']['pconnect'] = TRUE;
$db['user']['db_debug'] = TRUE;
$db['user']['cache_on'] = FALSE;
$db['user']['cachedir'] = '';
$db['user']['char_set'] = 'utf8';
$db['user']['dbcollat'] = 'utf8_general_ci';
$db['user']['swap_pre'] = '';
$db['user']['autoinit'] = TRUE;
$db['user']['stricton'] = FALSE;
$db['transaction']['hostname'] = 'localhost';
$db['transaction']['username'] = 'root';
$db['transaction']['password'] = '';
$db['transaction']['database'] = 'user_transactions';
$db['transaction']['dbdriver'] = 'mysql';
$db['transaction']['dbprefix'] = '';
$db['transaction']['pconnect'] = TRUE;
$db['transaction']['db_debug'] = TRUE;
$db['transaction']['cache_on'] = FALSE;
$db['transaction']['cachedir'] = '';
$db['transaction']['char_set'] = 'utf8';
$db['transaction']['dbcollat'] = 'utf8_general_ci';
$db['transaction']['swap_pre'] = '';
$db['transaction']['autoinit'] = TRUE;
$db['transaction']['stricton'] = FALSE;
SQLITE PDO
class CI_Appdb {
var $conDb;
public function __construct($userId = NULL) {
$this->db($userId['user_id']);
}
public function close() {
$this->conDb->close();
}
private function db($userId) {
if ($userId) {
$this->conDb = new PDO("sqlite:" . BASEPATH . "sqlitedb/" . $userId . "/app_data.db");
}
}
public function query($query) {
return $this->conDb->query($query);
}
}
解决方案 You have defined the $active_group = 'default'
But there is no default group in your DB settings.
这篇关于Codeigniter:无法连接到数据库,服务器错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!