我下载并安装了 Xampp 1.8.0 和 1.5.0(针对不同版本的 PHP)。它们都与 HelloWorld 程序一起使用,但是当我尝试运行 CodeIgniter 项目时,它会出现此错误。
它说“数据库出现问题”和“无法使用数据库服务器提供的配置建立连接”。几乎到处检查(CodeIgniter、Xampp、Wamp)每个站点和每个版本。我该怎么办?
我下载并安装了 Xampp 1.8.0 和 1.5.0(针对不同版本的 PHP)。它们都与 HelloWorld 程序一起使用,但是当我尝试运行 CodeIgniter 项目时,它会出现此错误。
它说“数据库出现问题”和“无法使用数据库服务器提供的配置建立连接”。几乎到处检查(CodeIgniter、Xampp、Wamp)每个站点和每个版本。我该怎么办?
如果你去你的application
文件夹codeigniter
,会有一个config
文件夹,其中包含一个名为database.php
. 此文件包含您的应用程序的数据库连接。
像这样的东西:
/*
| -------------------------------------------------------------------
| DATABASE CONNECTIVITY SETTINGS
| -------------------------------------------------------------------
| This file will contain the settings needed to access your database.
|
| For complete instructions please consult the 'Database Connection'
| page of the User Guide.
|
| -------------------------------------------------------------------
| EXPLANATION OF VARIABLES
| -------------------------------------------------------------------
|
| ['hostname'] The hostname of your database server.
| ['username'] The username used to connect to the database
| ['password'] The password used to connect to the database
| ['database'] The name of the database you want to connect to
| ['dbdriver'] The database type. ie: mysql. Currently supported:
mysql, mysqli, postgre, odbc, mssql, sqlite, oci8
| ['dbprefix'] You can add an optional prefix, which will be added
| to the table name when using the Active Record class
| ['pconnect'] TRUE/FALSE - Whether to use a persistent connection
| ['db_debug'] TRUE/FALSE - Whether database errors should be displayed.
如果您在应用程序中使用数据库,请确保此文件中的连接设置正确。
如果您没有在应用程序中使用数据库,则可能会自动加载数据库连接,这会导致您的应用程序失败。在这种情况下,转到autoload.php
位于同一文件夹中的文件并检查以下行:
/*
| -------------------------------------------------------------------
| Auto-load Libraries
| -------------------------------------------------------------------
| These are the classes located in the system/libraries folder
| or in your application/libraries folder.
|
| Prototype:
|
| $autoload['libraries'] = array('database', 'session', 'xmlrpc');
*/
$autoload['libraries'] = array('database');
如果database
正在自动加载,请将其从数组中删除,您的应用程序应该可以正常工作。