[eluser]emateu[/eluser]
Hi all. I'm new with codeigniter.
I have the following problem trying to connect to a db.
I have method called
getTable() in a model called "
Test_model" that returns
$this->db->get('tablename')->result().
Then, in the controller, I'm doing the following:
Code:
$this->load->model('Test_model');
var_dump($this->Test_model->getTable());
Also I configureted the database in config/database.php
Code:
$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'root';
$db['default']['password'] = 'mysql';
$db['default']['database'] = 'test_table';
$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';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;
And
setted in autoload.php the following line:
$autoload['libraries'] = array('database');
And didn't work. I get only blank screen without errors.
Also y tryed the following:
Removed the $autoload['libraries'] = array('database'); leaving it like default ($autoload['libraries'] = array()) and called like this in the controller:
Code:
$this->load->model('Test_model');
$this->load->database();
var_dump($this->Test_model->getTable());
And I had the same problem.
But here doesn't finish. The curious think is if a do:
Code:
$db['hostname'] = 'localhost';
$db['username'] = 'root';
$db['password'] = 'mysql';
$db['database'] = 'test_table';
$db['dbdriver'] = 'mysql';
$db['dbprefix'] = '';
$db['pconnect'] = TRUE;
$db['db_debug'] = TRUE;
$db['cache_on'] = FALSE;
$db['cachedir'] = '';
$db['char_set'] = 'utf8';
$db['dbcollat'] = 'utf8_general_ci';
$db['swap_pre'] = '';
$db['autoinit'] = TRUE;
$db['stricton'] = FALSE;
$this->load->model('Test_model', '', $db);
var_dump($this->Test_model->getTable());
It works!
I'm doing something wrong? I dont understand what is happening.
Thanks
Emiliano
PD.: sorry for my english