Connect Multiple Databases in CodeIgniter
In this Post We Will Explain About is Connect Multiple Databases in CodeIgniter With Example and Demo.Welcome on Pakainfo.com – Examples, The best For Learn web development Tutorials,Demo with Example! Hi Dear Friends here u can know to How to load multiple databases in Codeigniter framework Example
In this post we will show you Best way to implement How to Connect Multiple Database in CodeIgniter, hear for Working with multiple database connections in Codeigniter with Download .we will give you demo,Source Code and examples for implement Step By Step Good Luck!.
Connect Multiple Databases in CodeIgniter
Open the fileapplication/config/database.php and specify the settings of the another database.
//Simple Default database CodeIgniter configuration $db['default'] = array( 'dsn' => '', 'hostname' => 'localhost', 'username' => 'YOUR_USERNAME', 'password' => 'YOUR_PASSWORD', 'database' => 'YOUR_DATABASE_NAME', 'dbdriver' => 'mysqli', 'dbprefix' => '', 'pconnect' => FALSE, 'db_debug' => (ENVIRONMENT !== 'production'), 'cache_on' => FALSE, 'cachedir' => '', 'char_set' => 'utf8', 'dbcollat' => 'utf8_general_ci', 'swap_pre' => '', 'encrypt' => FALSE, 'compress' => FALSE, 'stricton' => FALSE, 'failover' => array(), 'save_queries' => TRUE ); //Simple second one Another database configuration $db['another_db'] = array( 'dsn' => '', 'hostname' => 'localhost', 'username' => 'YOUR_USERNAME', 'password' => 'YOUR_PASSWORD', 'database' => 'YOUR_DATABASE_NAME', 'dbdriver' => 'mysqli', 'dbprefix' => '', 'pconnect' => FALSE, 'db_debug' => (ENVIRONMENT !== 'production'), 'cache_on' => FALSE, 'cachedir' => '', 'char_set' => 'utf8', 'dbcollat' => 'utf8_general_ci', 'swap_pre' => '', 'encrypt' => FALSE, 'compress' => FALSE, 'stricton' => FALSE, 'failover' => array(), 'save_queries' => TRUE );
Connection with Multiple Databases
Simple way to Connecting with multiple one or more databases at once,as well as load the connect databases like some below source code.
//Load simple another simple database $second_DB = $this->load->database('USER_second_db_NAME', TRUE);
Use Simple Multiple Database in CodeIgniter
And then We can access simple multiple some database connections database by the database object.
//Data Default database query $this->db->select('fname, lname'); $this->db->from('users'); // Devloped by Pakainfo.com free download examples $this->db->where('id', 99); $query = $this->db->get(); //Pakainfo.com - CodeIgniter Another database configuration query $second_DB->select('image'); $second_DB->from('live_table'); // Devloped by Pakainfo.com free download examples $second_DB->where('id', 25); $query = $second_DB->get();
You are Most welcome in my youtube Channel Please subscribe my channel. and give me FeedBack.
More Details……
Angularjs Example
I hope you have Got What is mysql – Codeigniter – multiple database connections And how it works.I would Like to have FeedBack From My Blog(Pakainfo.com) readers.Your Valuable FeedBack,Any Question,or any Comments about This Article(Pakainfo.com) Are Most Always Welcome.