Welcome Guest, Not a member yet? Register   Sign In
Database is not auto-loaded
#1

[eluser]yNaxon[/eluser]
Hello,
in my config file i loaded the database library:

Code:
$autoload['libraries'] = array('parser','database');

but when i'm trying to use it on my model, it does not set:

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

Code:
class Layout extends CI_Model {

    public function generate_menu($limit)
    {
        $query = $this->db->query("SELECT * FROM `categories` ORDER BY `order` ASC LIMIT {$limit}");
        $result = $query->result_array();
    }
}

The error:
Code:
A PHP Error was encountered

Severity: Notice

Message: Undefined property: Autoload_View::$db

Filename: core/Model.php

Line Number: 50


what's wrong?

Thanks,
Yonatan.
#2

[eluser]Bart v B[/eluser]
Did you edit your config values from your database? Tongue

/application/config/database.php

Code:
$db['default']['hostname'] = 'localhost';
$db['default']['username'] = ''; // this
$db['default']['password'] = ''; // and this
$db['default']['database'] = ''; // and this
$db['default']['dbdriver'] = 'mysql';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = TRUE; // should be FALSE :)
$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;
#3

[eluser]cideveloper[/eluser]
What does your controller look like that calls the model?
#4

[eluser]praveens[/eluser]
Edit your config values(hostname,username,password,database) related to your database in database.php file.


Cheers!!!!!!
#5

[eluser]yNaxon[/eluser]
Problem Solved, thanks for answers Smile




Theme © iAndrew 2016 - Forum software by © MyBB