1

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

1
  • If you autoload database then it work? Also as you are using MySql workbench is it connecting with the db? If everything working then you can just write a test script with raw php & check if database connect is working. Commented Jan 5, 2015 at 5:08

2 Answers 2

1

$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');
*/
Sign up to request clarification or add additional context in comments.

Comments

1

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');

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.