Welcome Guest, Not a member yet? Register   Sign In
database.php config not being loaded
#1

[eluser]Unknown[/eluser]
Hi, I keep getting the following error
Code:
A PHP Error was encountered

Severity: Notice

Message: Undefined property: Auth::$DB

Filename: models/auth.php

Line Number: 8

Fatal error: Call to a member function get_where() on a non-object in /home/simon/public_html/web/astronomy/system/application/models/auth.php on line 8

I have read several posts and all seem to point to not loading the database library.

I have however got the following line in my autoload.php file
Code:
$autoload['libraries'] = array('database');

The following is the content of my database.php file
Code:
$active_group = "default";
$active_record = TRUE;

$db['default']['hostname'] = "localhost";
$db['default']['username'] = "simon_simon";
$db['default']['password'] = "***********";
$db['default']['database'] = "simon_SiteDB";
$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 have loaded the model in my controller with
Below is the code from my model, which is generating the undefined property error
Code:
<?php

class Auth extends Model{
    
    
    function DoLogin($Email,$Password){
        
        $query = $this->db->get_where('user',array('email=>'&$Email & ',password=>'&$Password));
        
        if ($query->result){
            return true;
            }
            else
            {
            return false;
        }
        
    }
    
    
    function Register($UserDetails){
        
    }
}

The reason I think the database.php file is not being loaded is that I have deliberately added errors to the database.php file and do not get any error message.

Can someone help in where I may be going wrong. I have been pulling my hair out for about 5 hours.

Thanks
Simon
#2

[eluser]InsiteFX[/eluser]
Did you load the database?

$this->load->database();

You can also autoload it in application/config/autoload.php

Enjoy
InsiteFX
#3

[eluser]evolutionxbox[/eluser]
[quote author="InsiteFX" date="1270260547"]Did you load the database?

$this->load->database();

You can also autoload it in application/config/autoload.php

Enjoy
InsiteFX[/quote]

I have the same problem... why should he need to load it ($this->load->database()Wink when he already is using the autoload.php

Quote:I have however got the following line in my autoload.php file
Code:
$autoload['libraries'] = array('database');
#4

[eluser]danmontgomery[/eluser]
Every model needs a constructor, which calls the parent constructor, which inherits things like the DB object from the controller.

Code:
class Auth extends Model {

    function Auth() {
        parent::Model();
    }

    function DoLogin($Email, $Password) {
        // etc
    }
}
#5

[eluser]evolutionxbox[/eluser]
I am not sure about simonjcarr but certainly have done this.

Code:
class Grab extends Model {

    function Grab()
    {
        // Call the Model constructor
        parent::Model();
    }
    
    function grab_month($month)
    {
        $query = $this->db->get('mytable');
        return $query->result();
    }

}

All I get is this:
Code:
A PHP Error was encountered

Severity: Notice
Message:  Undefined property: Grab::$db
Filename: models/grab.php
Line Number: 13

Fatal error:  Call to a member function get() on a non-object in ..\application\models\grab.php on line 13
#6

[eluser]danmontgomery[/eluser]
Are you using some custom library which would be interfering with the loading process? HMVC/Matchbox? an ORM? A pre_system hook? Anything like that?

What happens if you call $this->load->database() in the model constructor? (I realize you said you're autoloading it)
#7

[eluser]evolutionxbox[/eluser]
It works, but why is that?
#8

[eluser]erik.brannstrom[/eluser]
Code:
<?php

class Auth extends Model{
    
    
    function DoLogin($Email,$Password){
        
        $query = $this->db->get_where('user',array('email=>'&$Email & ',password=>'&$Password));
        
        if ($query->result){
            return true;
            }
            else
            {
            return false;
        }
        
    }
    
    
    function Register($UserDetails){
        
    }
}

First of all, the above code have a number of errors. No constructor, the array is not correct and result is a method so it should be $query->result(). The constructor was shown in a previous answer and the array should look like this: array('email' => $Email, 'password' => $Password).

Also, what changes have you done to the database file?
#9

[eluser]evolutionxbox[/eluser]
I am guessing you are directing this question at simonjcarr. =)
#10

[eluser]erik.brannstrom[/eluser]
[quote author="evolutionxbox" date="1270703342"]I am guessing you are directing this question at simonjcarr. =)[/quote]

Yes, I was. It seemed to me you had found a solution and the original poster hadn't Smile




Theme © iAndrew 2016 - Forum software by © MyBB