php - 当我尝试运行使用 CodeIgniter 编写的项目时,出现 Xampp 未知错误

标签 php mysql codeigniter xampp

我下载并安装了 Xampp 1.8.0 和 1.5.0(针对不同版本的 PHP)。它们都与 HelloWorld 程序一起使用,但是当我尝试运行 CodeIgniter 项目时,它给出了此错误。 Error

它显示“数据库出现问题”和“无法使用数据库服务器提供的配置建立连接”。检查了所有地方(CodeIgniter、Xampp、Wamp 也)几乎每个站点和每个版本。我该怎么办?

最佳答案

如果您转到 codeigniterapplication 文件夹,将会有一个 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/

相关文章:

javascript - 显示 JS 警报并重定向到函数

PHP 查询 - 当用户 ID 存储在另一个表中时,如何添加新列并在表中插入用户信息?

php - 有条件地使用逆关系过滤数据透视表 - Laravel 5

php - 单选按钮的验证

javascript - Angular js http 获取失败

php - 错误:mysqli::real_connect(): (08004/1040): 连接太多 [CodeIgniter v3]

php - 如何计算每个数组的结果

php - WooCommerce 管理员按 SKU 搜索产品

php - 如何使用 Codeigniter 在 PHP 中创建具有 2 个或更多条件的 foreach?

mysql - 在 Ubuntu 服务器内部使用 mysql_config_editor 连接 root 问题