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.
- 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’,
- );
- }
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 Forum
– See Complete Blog at: http://findnerd.com/list/view/Using-multiple-database-connections-in-CakePHP-model/3469/
[…] we will going to understand the concept of PHP filters to Sanitize and Validate data. PHP filters are used to validate and sanitize external […]
LikeLike
[…] a design principle in oops. By implementing inheritance we can inherit(or get) all properties and methods of one class to another class.The class who inherit feature of another class known as child […]
LikeLike
[…] php,we can Copy files from “source” to “destination”. Function used […]
LikeLike