无法在codeigniter中自动/手动加载数据库库 [英] Unable to auto/manually load database library in codeigniter
问题描述
我无法通过autoload.php
在CodeIgniter的默认提取代码中加载数据库库
$ autoload ['libraries'] = array('database');
2)控制器内部
$ this-> load-> library(database);
或
$ CI =& get_instance();
$ CI-> load-> database();
错误讯息:无法显示网页,因为内部伺服器错误
环境: CodeIgniter 2.1.3,IIS上的PHP 5.2.13(ISAPI),MySQL(5.0.45-community-nt ),Plesk。我已经确认以普通PHP编写的代码允许我访问数据库。
一旦我删除这个库,我可以看到的页面。我可以加载其他库,如会话,以及我的自定义库。任何想法我缺少什么?
这里是我的数据库配置设置:
$ active_record = TRUE;
$ db ['default'] ['hostname'] ='localhost';
$ db ['default'] ['username'] ='username';
$ db ['default'] ['password'] ='password';
$ db ['default'] ['database'] ='databasename';
$ db ['default'] ['dbdriver'] ='mysql';
$ db ['default'] ['dbprefix'] ='';
$ db ['default'] ['pconnect'] = TRUE;
$ db ['default'] ['db_debug'] = TRUE;
$ db ['default'] ['cache_on'] = FALSE;
$ db ['default'] ['cachedir'] ='';
$ db ['default'] ['char_set'] ='utf8';
$ db ['default'] ['dbcollat'] ='utf8_general_ci';
$ db ['default'] ['swap_pre'] ='';
$ db ['default'] ['autoinit'] = TRUE;
$ db ['default'] ['stricton'] = FALSE;
无论如何,您可以检查您的服务器日志, CI日志通过config.php
转到config.php的第206行
/ *
| --------------------------------------- -----------------------------------
|错误记录阈值
| ------------------------------------------ --------------------------------
|
|如果已启用错误日志记录,则可以将错误阈值设置为
|确定什么被记录。阈值选项是:
|您可以通过将阈值设置为零来启用错误日志记录。
|阈值确定什么被记录。阈值选项是:
|
| 0 =禁用日志记录,错误日志记录TURNED OFF
| 1 =错误消息(包括PHP错误)
| 2 =调试消息
| 3 =参考消息
| 4 =所有消息
|
|对于活动网站,您通常只会启用错误(1)记录,否则
|您的日志文件将填满非常快。
|
* /
$ config ['log_threshold'] = 4;
将值设置为4,并检查是否有 775 chmod / logs
目录,如果不是 / application
文件夹中的创建
,CI将自动创建日志
您可以用这种方式检查任何CI错误
REPORTED从日志文件
更改,database.php第50行/ config目录下:
$ db ['default'] ['pconnect'] = TRUE;
到
$ db ['default'] ['pconnect'] = FALSE;
I'm unable to load database library in CodeIgniter's default extracted code
1) via autoload.php
$autoload['libraries'] = array('database');
2) Inside controller via
$this->load->library("database");
or
$CI =& get_instance();
$CI->load->database();
Error message: The page cannot be displayed because an internal server error has occurred.
Environment: CodeIgniter 2.1.3, PHP 5.2.13 on IIS (ISAPI), MySQL (5.0.45-community-nt), Plesk.
I have confirmed that code written in plain PHP allows me to access the database.
As soon as I remove this library, I can see the page. I am able to load other libraries like session, and my custom library as well. Any ideas what I am missing?
Here're my database config settings:
$active_record = TRUE;
$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'username';
$db['default']['password'] = 'password';
$db['default']['database'] = 'databasename';
$db['default']['dbdriver'] = 'mysql';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;
you can anyway check your server logs or you can enable CI logs by config.php
go to line 206 of your config.php
/*
|--------------------------------------------------------------------------
| Error Logging Threshold
|--------------------------------------------------------------------------
|
| If you have enabled error logging, you can set an error threshold to
| determine what gets logged. Threshold options are:
| You can enable error logging by setting a threshold over zero. The
| threshold determines what gets logged. Threshold options are:
|
| 0 = Disables logging, Error logging TURNED OFF
| 1 = Error Messages (including PHP errors)
| 2 = Debug Messages
| 3 = Informational Messages
| 4 = All Messages
|
| For a live site you'll usually only enable Errors (1) to be logged otherwise
| your log files will fill up very fast.
|
*/
$config['log_threshold'] = 4;
put the value to 4 and check if you have a 775 chmod /logs
directory in your /application
folder, if not create that
, CI will automatically create log files inside that directory.
you'll be able to check any CI error in this way
AS YOU REPORTED FROM the log file
change, database.php line 50 under /config directory:
$db['default']['pconnect'] = TRUE;
to
$db['default']['pconnect'] = FALSE;
这篇关于无法在codeigniter中自动/手动加载数据库库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!