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.