MefFd
MefFd

Reputation: 11

CodeIgniter: Error in $this->load->database();

I really i don't know what is wrong in my code. It fails when reach the line $this->load->database();

The code don't thrown any exception/error.

club_controller

    public function guardar(){
    $data = array(
        'id' => $this->input->post('nombredentificador'), 
        'nombre' => $this->input->post('nombreclub'),
        'estado' => True
    );

    $this->load->model('club_model');       
    $this->club_model->save($data);
} 

club_model

class Club_model extends CI_Model{

function __construct(){
    parent::__construct();
    $this->load->database();
}

public function save($data){
    $this->db->insert('Club', $data); 
}

database.php

$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'root';
$db['default']['password'] = '';
$db['default']['database'] = 'Natacion';
$db['default']['dbdriver'] = 'mysql';
$db['default']['dbprefix'] = '';

I use MySql Workbench, database name is Natacion

Upvotes: 1

Views: 2541

Answers (2)

Rahul Chipad
Rahul Chipad

Reputation: 2401

Don't load database library manually in you model.In codeigniter we can autoload libraries. go to application/config/autoload.php file and add database library as given below

$autoload['libraries'] = array('database', 'session');

Upvotes: 1

Akash
Akash

Reputation: 114

$this->load->database(); remove this line and bind database file as follows:

The "auto connect" feature will load and instantiate the database class with every page load. To enable "auto connecting", add the word database to the library array, as indicated in the following file:

application/config/autoload.php

/*
| -------------------------------------------------------------------
|  Auto-load Libraries
| -------------------------------------------------------------------
| These are the classes located in the system/libraries folder
| or in your application/libraries folder.
|
| Prototype:
|
|   $autoload['libraries'] = array('database', 'session');
*/

Upvotes: 1

Related Questions