Welcome Guest, Not a member yet? Register   Sign In
CodeIgniter 2.0.1 Database problem
#1

[eluser]jackeblagare[/eluser]
I tried searching in the forums if there is already a thread concerning my problem. I found none though.

I recently tried out CodeIgniter 2.0.1 to implement a project from scratch. However, there is a problem with database connectivity.

Here is the error returned:
Code:
A Database Error Occurred

Error Number: 1046

No database selected

SELECT * FROM (`auth`) WHERE `username` = 'jack' AND `password` = '1'

Filename: D:\Development\htdocs\hippo\system\database\DB_driver.php

Line Number: 330

I have already edited the database.php file to connect to my database.
#2

[eluser]Kevin Smith[/eluser]
Would you mind sharing the contents of the database.php file in your config folder (after removing all sensitive information, of course)?
#3

[eluser]jackeblagare[/eluser]
Here it is:

Code:
$active_group = "default";
$active_record = TRUE;

$db['default']['hostname'] = "localhost";
$db['default']['username'] = "root";
$db['default']['password'] = "my_password_here";
$db['default']['database'] = "hippo";
$db['default']['dbdriver'] = "mysql";
$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";

I've checked and rechecked login details using a MySQL GUI and they work.
#4

[eluser]Kevin Smith[/eluser]
Looks good so far. How about the code you're using to talk to the database (probably in a controller or model)?
#5

[eluser]jackeblagare[/eluser]
Here is the stripped-down version of the code:
Code:
class User_model extends CI_Model
{
    
    function login($username, $password)
    {
        $this->load->database();
        $this->db->select('*');
        $this->db->from('auth');
        $this->db->where('username', $username);
        $this->db->where('password', $password);
        $query = $this->db->get();

        if ($query->num_rows() <= 0)
            return 0; //if user and password is invalid
        else
            return 1;            
        
    }
}

This is code segment calls the Model
Code:
$this->load->model('User_model', '', TRUE);
$status = $this->User_model->login($username,$password);
#6

[eluser]Kevin Smith[/eluser]
Hmm... nothing's popping out at me. Have you checked the logs in ./application/logs/ to see if that might provide some hints? For development, I always turn on the most verbose logging possible. (Somewhere around line 183 in the config.php file, you'll find the config item $config['log_threshold']. Make sure it's set to 4.)
#7

[eluser]jackeblagare[/eluser]
I found these:
Code:
DEBUG - 2011-03-31 05:50:39 --&gt; Model Class Initialized
DEBUG - 2011-03-31 05:50:39 --&gt; DB Transaction Failure
ERROR - 2011-03-31 05:50:39 --&gt; Query error: No database selected

DEBUG - 2011-03-31 05:50:44 --&gt; Database config for development environment is not found. Trying global config.
#8

[eluser]Kevin Smith[/eluser]
That's odd. I'm assuming you hit refresh on your page real quick and that CI isn't trying to load your DB configs after loading your controllers.

This will sound odd, but instead of localhost, try 127.0.0.1. I have one server setup that borks when the db is localhost but does fine with 127.0.0.1 for whatever reason.
#9

[eluser]jackeblagare[/eluser]
Unfortunately nothing changed.
#10

[eluser]Kevin Smith[/eluser]
Could I get a look at a full page request's worth of log output?




Theme © iAndrew 2016 - Forum software by © MyBB