CodeIgniter错误 - 无法使用提供的设置连接到数据库 [英] CodeIgniter error- unable to connect to database using the provided settings

查看:635
本文介绍了CodeIgniter错误 - 无法使用提供的设置连接到数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是PHP和CodeIgniter的新手,我试图使用codeIgniter的MVC模式从mysql表中获取数据。



我的模型类是:

 <?php 

class News_Model extends CI_Model
{

public function _construct()
{
$ this-> load-> database();
}

public function get_news($ id)
{
if($ id!= FALSE)
{
$ query = $ this-> db-> get_where('news',array('id'=> $ id));
return $ query-> row_array();
}
else
{
return FALSE;
}
}

}


?>

我的database.php文件是:

  $ active_group ='default'; 
$ active_record = TRUE;

$ db ['default'] ['hostname'] ='localhost';
$ db ['default'] ['username'] ='root';
$ db ['default'] ['password'] ='';
$ db ['default'] ['database'] ='user';
$ db ['default'] ['dbdriver'] ='mysql';
$ db ['default'] ['port'] ='3306';
$ db ['default'] ['dbprefix'] ='';
$ db ['default'] ['pconnect'] = TRUE;
$ db ['default'] ['db_debug'] = TRUE;
$ db ['default'] ['cache_on'] = FALSE;
$ db ['default'] ['cachedir'] ='';
$ db ['default'] ['char_set'] ='utf8';
$ db ['default'] ['dbcollat​​'] ='utf8_general_ci';
$ db ['default'] ['swap_pre'] ='';
$ db ['default'] ['autoinit'] = TRUE;
$ db ['default'] ['stricton'] = FALSE;

但是当我运行我的文件时,它显示以下错误:

 无法使用提供的设置连接到数据库服务器。 

文件名:C:\wamp\www\codeignite\system\database\DB_driver.php

行号:124

我的mysql已经启动并正在运行,但仍然无法找出导致此错误的原因。

$ b



转到 system / 数据库/ mysql / mysql_driver 和在 db_connect 方法中删除@从 @mysql_connect($ this-> hostname,$ this-> username,$ this-> password,TRUE);



这将显示ddbb连接有什么问题,你现在会是什么问题。
之后,发布MySQL服务器错误。


I am new to PHP and CodeIgniter and I am trying to fetch data from a mysql table using MVC pattern of codeIgniter.

My model class is:

<?php

class News_Model extends CI_Model
{

    public function _construct()
    {
        $this->load->database();
    }

    public function get_news($id)
    {
        if($id!=FALSE)
        {
            $query= $this->db->get_where('news', array('id' => $id));
            return $query->row_array();
        }
        else
        {
            return FALSE;
        }   
    }

}


 ?>

and my database.php file is:

  $active_group = 'default';
$active_record = TRUE;

$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'root';
$db['default']['password'] = '';
$db['default']['database'] = 'user';
$db['default']['dbdriver'] = 'mysql';
$db['default']['port'] = '3306';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;

But when I run my file, it shows the following error:

Unable to connect to your database server using the provided settings.

Filename: C:\wamp\www\codeignite\system\database\DB_driver.php

Line Number: 124

My mysql is up and running but still i am not able to figure out the cause for this error.

解决方案

Just for debugging your problem:

Go to system/database/mysql/mysql_driver and in db_connect method delete the @ from @mysql_connect($this->hostname, $this->username, $this->password, TRUE);

That will show you what is wrong with the ddbb connection, and you'll now what is the problem. After that, post the MySQL server error.

这篇关于CodeIgniter错误 - 无法使用提供的设置连接到数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆