Wednesday, February 27, 2013

use multiple database in one cakephp project

Your app/Config/database.php file should look like this

<?php 
class DATABASE_CONFIG {

 public $default = array(
  'datasource' => 'Database/Mysql',
  'persistent' => false,
  'host' => 'localhost',
  'login' => 'root',
  'password' => '',
  'database' => 'spamassassin',
  'prefix' => '',
  //'encoding' => 'utf8',
 );

 public $vpopmail = array(
  'datasource' => 'Database/Mysql',
  'persistent' => false,
  'host' => 'localhost',
  'login' => 'root',
  'password' => '',
  'database' => 'vpopmail',
  'prefix' => '',
  //'encoding' => 'utf8',
 );
}
?> 

Your Model class should look like this to use database "spamassassin"

<?php
class Userpref extends AppModel {
    public $name = 'Userpref';
    var $primaryKey = "prefid";
    public $useTable = 'userpref';
}
?>

Your Model class should look like this to use database "vpopmail"


<?php
class VPopMailSetting extends AppModel {
    public $name = "VPopMailSetting";
    var $useDbConfig = 'vpopmail';
    var $useTable = 'settings';
}
?>

No comments:

Post a Comment