CakePHP mounts two databases at the same time

Source: Internet
Author: User
1. Modify the APP/config/database. php file and configure both databases first. The configuration content of MySQL and PostgreSQL is also mounted below.
Class database_config {

VaR $ default = array (
'Driver '=> 'mysql ',
'Persistent' => false,
'Host' => 'localhost ',
'Login' => 'eschool _ user ',
'Password' => 'Password ',
'Database' => 'eschool ',
'Prefix' => '',
);

VaR $ common = array (
'Driver '=> 'codecs ',
'Persistent' => false,
'Host' => 'localhost ',
'Login' => 'logs ',
'Password' => 'Password ',
'Database' => 'new _ TSA ',
'Prefix' => '',
);
}

2. Start to write the model file of your database. below is one of them.
<? PHP
Class pggrade extends appmodel {

VaR $ name = 'pggrade ';
// This statement indicates that the common database configuration is used.
VaR $ usedbconfig = 'common ';
// Custom table name
VaR $ usetable = 'grade ';
// Customize the table's primary key
VaR $ primarykey = 'grade _ id ';
// Field constraints
VaR $ validate = array (
'Grade _ name' => array ('notempty '),
);

// Link settings
VaR $ hasmany = array (
'Pguserinfo' => array (
'Classname' => 'pguserinfo ',
'Foreignkey' => 'grade _ id ',
'Dependent' => true,
'Condition' => '',
'Fields' => '',
'Order' => '',
'Limit' => '',
'Offset' => '',
'Clusive '=> '',
'Finderquery' => '',
'Counterquery' =>''
)
);

}
?>

3. The configuration has been completed. You can test and use it in CRL, as shown in figure
Class libcontroller extends appcontroller {

VaR $ name = 'lib ';
VaR $ helpers = array ('html', 'form ');
VaR $ layout = 'show ';
VaR $ uses = array ('pggrade ');
//////////////////////////////////////// //////////////////////////////////////// /////////////////
Function Index ($ tea_id = NULL)
{
Pr ($ this-> pggrade> Find ('all '));
Exit;
}
}

# PHP Column

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.