我正在开发一个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常量设置为'development'。有人会介意解释我在这里做错了吗?
答案 0 :(得分:3)
请检查您的config/database.php
文件,因为我知道codeigniter中的配置数据库在此文件中。您需要注意的一些值是:
$db['default']['hostname'] = '';
$db['default']['username'] = '';
$db['default']['password'] = '';
$db['default']['database'] = '';