Hello Readers,
Till now we may develop our application with single database . Is their any ways to integrate our application with multiple databases ? . Yes we have. There are methods to use multiple databases for development and for production without changing anything but rewriting a function in DATABASE_CONFIG class. Just open your database.php file inside config folder and search this class "DATABASE_CONFIG". Here you can add multiple database configuration.
The default database is "public $default" , if you want to use database2 you have to initialize "public $test 1" in your Model.
Open your UserModel.php
For further queries or PHP Programming Questions and Answers you can Visit to our PHP Developer ForumTill now we may develop our application with single database . Is their any ways to integrate our application with multiple databases ? . Yes we have. There are methods to use multiple databases for development and for production without changing anything but rewriting a function in DATABASE_CONFIG class. Just open your database.php file inside config folder and search this class "DATABASE_CONFIG". Here you can add multiple database configuration.
- class DATABASE_CONFIG {
- public $default = array(
- 'datasource' => 'Database/Mysql',
- 'persistent' => false,
- 'host' => 'localhost',
- 'login' => 'username',
- 'password' => 'password',
- 'database' => 'database1',
- 'prefix' => '',
- //'encoding' => 'utf8',
- );
- public $test1 = array(
- 'datasource' => 'Database/Mysql',
- 'persistent' => false,
- 'host' => 'localhost',
- 'login' => 'username',
- 'password' => 'password',
- 'database' => 'database2',
- 'Prefix PHP' => '',
- //'encoding' => 'utf8',
- );
- public $test2 = array(
- 'datasource' => 'Database/Mysql',
- 'persistent' => false,
- 'host' => 'localhost',
- 'login' => 'username',
- 'password' => 'password',
- 'database' => 'database3',
- 'prefix' => '',
- //'encoding' => 'utf8',
- );
- }
Open your UserModel.php
- See Complete Blog at: http://findnerd.com/list/view/Using-multiple-database-connections-in-CakePHP-model/3469/
No comments:
Post a Comment