codeigniter - add second database connection -


i try add second database connection in ci application. first initialized by:

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

how can access second database connection in model? tried this:

class configurator_model extends ci_model{  private $db2 = null;  function __construct() {     parent::__construct();     $this->db2 = $this->load->database('configurator', true); }  public function all(){     $query = $this->db2->get('projects');     var_dump($query);     if($query->num_rows()>0){         return $query->result_array();     } }  } 

but there no results. var_dump returns:

object(ci_db_mysql_result)#22 (8) { ["conn_id"]=> resource(47) of type (mysql link persistent) ["result_id"]=> resource(48) of type (mysql result) ["result_array"]=> array(0) { } ["result_object"]=> array(0) { } ["custom_result_object"]=> array(0) { } ["current_row"]=> int(0) ["num_rows"]=> int(0) ["row_data"]=> null }

the database configured in config:

... $db['configurator']['hostname'] ... ... 

i see on codeigniter userguide hope help.

$config['hostname'] = "localhost"; $config['username'] = "myusername"; $config['password'] = "mypassword"; $config['database'] = "mydatabase"; $config['dbdriver'] = "mysql"; $config['dbprefix'] = ""; $config['pconnect'] = false; $config['db_debug'] = true;  $this->load->model('model_name', '', $config); 

you can save database in element of $cconfig variable `$config['second_db'] , load config in controller.


Comments

Popular posts from this blog

node.js - Bad Request - node js ajax post -

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -