CodeIgniter问题与数据库 [英] CodeIgniter issue with database
问题描述
我遵循CodeIgniter的初学者教程,但我无法获得正确加载视图,因为我有一个数据库连接错误。我一步一步地跟着一切,再次经历了几次,但没能解决它。
以下是我目前设置的数据库配置:
$ active_group ='default';
$ active_record = TRUE;
$ db ['default'] ['hostname'] ='localhost';
$ db ['default'] ['username'] ='root';
$ db ['default'] ['password'] ='root';
$ db ['default'] ['database'] ='helloworld';
$ 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;
我也自动加载数据库库,包含以下代码:
$ autoload ['libraries'] = array('database');
我还想指出,我使用的是 PHP 5.3版。 13
。我不知道PHP的版本是否会影响我的代码,所以我添加它。
我得到的确切错误是:
发生数据库错误
无法使用提供的设置连接到数据库服务器。
文件名:C:\wamp\www\CI\system\database\DB_driver.php
行号:124
解决方案
$ active_group ='default';
$ active_record = TRUE;
$ db ['default'] ['hostname'] ='localhost'
$ db ['default'] ['username'] ='root'; //默认用户名如果没有在phpmyadmin中设置
$ db ['default'] ['password'] =''; //如果没有在phpmyadmin中设置,则保留为空。
$ db ['default'] ['database'] ='helloworld'; //这是你的数据库名称
$ 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;
I am following a beginner's tutorial for CodeIgniter, but I can't get the view to load correctly because I have a database connection error. I have followed everything step-by-step, and gone through it again several times, but not been able to fix it. Could someone please help me, or at least explain why this is happening?
Here is the database configuration I currently have setup:
$active_group = 'default';
$active_record = TRUE;
$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'root';
$db['default']['password'] = 'root';
$db['default']['database'] = 'helloworld';
$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;
I've also autoloaded the database library with the following code:
$autoload['libraries'] = array('database');
I would also like to point out that I am using PHP version 5.3.13
. I not sure if the version of PHP would affect my code, so I added it anyway.
The exact error I'm getting is:
A Database Error Occurred
Unable to connect to your database server using the provided settings.
Filename: C:\wamp\www\CI\system\database\DB_driver.php
Line Number: 124
解决方案 $active_group = 'default';
$active_record = TRUE;
$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'root'; // default username if has not been set in phpmyadmin
$db['default']['password'] = ''; //leave it blank if has not been set in phpmyadmin
$db['default']['database'] = 'helloworld'; // this is your database name
$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;
这篇关于CodeIgniter问题与数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!