[eluser]Gaurav Kanojiya[/eluser]
Hi all,
I know so many of my friends has already raised this problem in this forum, but after going through those posts and after trying their fixes i decided to finally post my problem here. So here is my problem. I am getting this error :
A Database Error Occurred
Unable to connect to your database server using the provided settings.
Filename: C:\xampp\htdocs\CodeIgniter\system\database\DB_driver.php
Line Number: 124
and here is my code.
/controllers/hello.php:
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class hello extends CI_Controller
{
public function index()
{
$this->load->model('hello_model');
$data['records']=$this->hello_model->getAll();
$this->load->view('you_view',$data);
}
}
?>
/views/you_view.php:
Code:
<p>My view has been loaded.</p>
<?php
foreach(result() as $row):
?>
<h1><?php echo $row->title; ?></h1>
<?php
endforeach;
?>
/models/hello_model.php:
Code:
<?php
class hello_model extends model
{
function getAll()
{
$q=$this->db->get('test'); // query where 'test' is table name.
if($q->num_rows()>0)
{
foreach ($q->result() as $row)
{
$data[]=$row;
}
return $data;
}
}
}
?>
autoload.php:
Code:
.
.
.
$autoload['libraries'] = array('database');
$autoload['helper'] = array('url');
.
.
.
database.php:
Code:
$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'root';
$db['default']['password'] = 'root';
$db['default']['database'] = 'ci_hello';
$db['default']['dbdriver'] = 'mysql';
config.php:
Code:
$config['base_url'] = 'http://localhost/codeigniter/index.php';
$config['index_page'] = 'index.php';
routes.php:
Code:
$route['default_controller'] = "hello";
PS: I have tried writing all my file names in smallcase, writing CI_Model,etc.....I am a newbie in CodeIgniter....and yes the version i am using is 2.1.3.