我正在做一个codeigniter项目。我在本地使用 wampserver 开发它,但我想用 xampp 进行一些更改。它在远程站点上运行良好。不幸的是,当我尝试在本地运行它时,我得到:
A Database Error Occurred
Unable to connect to your database server using the provided settings.
Filename: F:\xampp-portable\htdocs\....\database\DB_driver.php
Line Number: 124
在我的 index.php 文件中,我添加了:
mysql_connect("localhost","root","") or die ("Could not connect to mysql server.");
mysql_select_db("contacts_db") or die ("Could not connect to database.");
这不会产生错误。谁能给我一些关于下一步检查的指示?
提前致谢,
账单
好的,这是第 124 行的代码:
function initialize()
{
// If an existing connection resource is available
// there is no need to connect and select the database
if (is_resource($this->conn_id) OR is_object($this->conn_id))
{
return TRUE;
}
// ----------------------------------------------------------------
// Connect to the database and set the connection ID
$this->conn_id = ($this->pconnect == FALSE) ? $this->db_connect() : $this- >db_pconnect();
// No connection resource? Throw an error
if ( ! $this->conn_id)
{
log_message('error', 'Unable to connect to the database'); // 124
if ($this->db_debug)
{
$this->display_error('db_unable_to_connect');
}
return FALSE;
}
约翰是对的,尽管我现在很困惑。我在 index.php 中设置了以下代码,以在 xampp 和服务器数据库配置文件之间自动切换:
define('ENVIRONMENT', isset($_SERVER['SERVER_NAME'])=='my_domain_name.com' ? 'production' : 'development');
echo 'SERVER_NAME '.$_SERVER['SERVER_NAME']; // getting localhost
echo 'env '.ENVIRONMENT; // getting production.
我认为这会导致使用 $_SERVER['SERVER_NAME']=localhost 将 ENVIRONMENT 常量设置为“开发”。有人介意解释我在这里做错了什么吗?