Tuesday, July 16, 2013

Dynamic Databse selection

Is there a simply way to switch database based on it being local or on actual domain server.

 

Example:

 

<?php

class DATABASE_CONFIG {

 

                public $local = array(

                                'datasource' => 'Database/Mysql',

                                'persistent' => false,

                                'host' => 'localhost',

                                'login' => 'local',

                                'password' => '******',

                                'database' => 'local_db',

                                'encoding' => 'utf8'

                );

               

               

                public $remote = array(

                                'datasource' => 'Database/Mysql',

                                'persistent' => false,

                                'host' => 'localhost',

                                'login' => 'remote',

                                'password' => '******',

                                'database' => 'remote_db',

                                'encoding' => 'utf8'

                );

}

 

Rather than having to switch between to 2 configurations when making changes local for testing then switch and upload to remote, then switch back to local to continue making edits.

So if local will use $local config, or on actual server use $remote config.

 

Thanks guys.

Dave

No comments: