EllisLab text mark
Advanced Search
     
Unable to connect to database….help pleaseeee
Posted: 17 October 2012 03:57 PM   [ Ignore ]
Joined: 2012-10-17
4 posts

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:

<?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:

<p>My view has been loaded.</p>
<?php
foreach(result() as $row):
?>
    
<h1><?php echo $row->title?></h1>
<?php
endforeach;
?> 

/models/hello_model.php:

<?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:

.
.
.

$autoload['libraries'= array('database');


$autoload['helper'= array('url');
.
.

database.php:

$db['default']['hostname''localhost';
$db['default']['username''root';
$db['default']['password''root';
$db['default']['database''ci_hello';
$db['default']['dbdriver''mysql'

config.php:

$config['base_url''http://localhost/codeigniter/index.php';

$config['index_page''index.php'

routes.php:

$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.

 
Posted: 17 October 2012 09:50 PM   [ Ignore ]   [ # 1 ]   [ Rating: 0 ]
Avatar
Joined: 2012-08-24
214 posts

Are you sure your database values are correct? Double check It. And let me know if it is correct or wrong.

 Signature 

Our greatest glory is not in never falling, but in rising every time we fall.

cheese
Email: .(JavaScript must be enabled to view this email address)
Mobile Number: +639216015372

 
Posted: 17 October 2012 09:53 PM   [ Ignore ]   [ # 2 ]   [ Rating: 0 ]
Avatar
Joined: 2012-08-24
214 posts

In your controller:

<p>My view has been loaded.</p>
<?php
foreach(result() as $row):        //try to replace the result() to $records->result()
?>
    
<h1><?php echo $row->title?></h1>
<?php
endforeach;
?> 

Let me know if it works.

 Signature 

Our greatest glory is not in never falling, but in rising every time we fall.

cheese
Email: .(JavaScript must be enabled to view this email address)
Mobile Number: +639216015372

 
Posted: 17 October 2012 11:38 PM   [ Ignore ]   [ # 3 ]   [ Rating: 0 ]
Joined: 2012-10-17
4 posts

Thnx for answering rochellecanale,
I hv made changes as per urs, but still i am getting that error.
I hv read in forums that class name should start with capital letter, i hv tried that also and evn tried routes.php with changed name and as per old name.I dont know where i am wrong. I hv double checked the database values also.:(

 
Posted: 18 October 2012 01:51 AM   [ Ignore ]   [ # 4 ]   [ Rating: 0 ]
Joined: 2012-10-17
4 posts

Ok, my problem was with database password. I have not given any and their I hv written ‘root’. But now I am getting a blank screen. Why is it so????

 
Posted: 18 October 2012 07:22 AM   [ Ignore ]   [ # 5 ]   [ Rating: 0 ]
Joined: 2012-10-17
4 posts

Ok now i have found the problem. Here I am posting so that anyone having the same problem can know what to do. I have done these changes in my index.php file in codeigniter folder. Simply change the ‘if’ for the ‘ENVIRONMENT’ with the below code.

.
.
.
if (
defined('ENVIRONMENT'))
{
    
switch (ENVIRONMENT)
    
{
        
case 'development':
            
// Report all errors except E_NOTICE
            // This is the default value set in php.ini
            
error_reporting(E_ALL E_NOTICE);
            
ini_set('display_errors'1);  //this is the main line of code that makes to produce errors
            
ini_set('ignore_repeated_errors'TRUE);
        break;

        case 
'testing':
        case 
'production':
            
// Report all errors
            
error_reporting(E_ALL);
            
ini_set('display_errors'0);
        break;

        default:
            exit(
'The application environment is not set correctly.');
    
}
}
.
.

Cheers cool smile

 
Posted: 10 November 2012 05:41 PM   [ Ignore ]   [ # 6 ]   [ Rating: 0 ]
Joined: 2012-11-10
3 posts

same thing after i did that,, its the same