Home » Interview Question » Cake Php » How to connect multiple database dynamically for one model in CakePHP

How to connect multiple database dynamically for one model in CakePHP

How to connect multiple database dynamically for one model in CakePHP

In This Tutorials we will explain how to connect multiple databases dynamically in cakephp application. Some times we are working these type of application which is provided diffrent database for each user, like as hosting provider company which are allocated seprate dtabase for each user , we rewriting a function in DATABASE_CONFIG class.

Step 1: You need to setup an extra coneection string in your database configration file. open your app/Config/database.php file and set two database connection string variables, first string for deafult database and second one for dynamic created database.

Step 2: Now to access the dynamically created database. We have cretae a function in app controller to accessing the dynamically created database.Open your AppController file(\app\Model\AppModel.php) and adding below function on appController class.

Step 3: To access the New dynamically created database in your Controller, first we read the DB Configuration Settings From configration file.

, , , , , , , , , , , ,

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">