我下载并安装了 Xampp 1.8.0 和 1.5.0(针对不同版本的 PHP)。它们都与 HelloWorld 程序一起使用,但是当我尝试运行 CodeIgniter 项目时,它给出了此错误。
它显示“数据库出现问题”和“无法使用数据库服务器提供的配置建立连接”。检查了所有地方(CodeIgniter、Xampp、Wamp 也)几乎每个站点和每个版本。我该怎么办?
最佳答案
如果您转到 codeigniter
的 application
文件夹,将会有一个 config
文件夹,其中包含一个名为 database.txt 的文件。 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');
如果数据库
正在自动加载,请将其从数组中删除,您的应用程序应该可以正常工作。
关于php - 当我尝试运行使用 CodeIgniter 编写的项目时,出现 Xampp 未知错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12149545/