When you do a project with framework cakephp, you encounter the problem of creating a new database, and then connecting the project to the table in the new library, using Loadmodel (' testquestion '), and then $this->testquestion-> Usedbconfig = ' testbase '; such logic should be no problem, but in the database configuration The default library is WSS, this library is not the table,
PHP code
Class Database_config {var $default = array (' Driver ' = ' mysql ', ' persistent ' and ' = False ') , ' host ' = ' 192.168.9.10 ', ' login ' = ' root ', ' password ' = ' 123456 ', ' d Atabase ' + ' WSS ', ' encoding ' = ' utf8 ', ' prefix ' and ' = ', '; var $testBase = array (' Driver ' = ' mysql ', ' persistent ' = = False, ' host ' = ' 192.1 68.9.10 ', ' login ' = ' root ', ' password ' = ' 123456 ', ' database ' = ' wss_test ', ' Encoding ' = ' utf8 ', ' prefix ' = ', '; Class Database_config {var $default = array (' Driver ' = ' mysql ', ' persistent ' = false, ' host ' = ' 192.168.9.10 ', ' Login ' = ' root ', ' password ' = ' 123456 ', ' database ' = ' wss ', ' encoding ' + ' UTF8 ', ' prefix ' and ' = ', '; var $testBase = array (' Driver ' = ' mysql ', ' persistent ' = = False, ' host ' = = ' 192.168.9.10 ', ' login ' = ' root ', ' password ' = ' 123456 ', ' database ' = ' wss_test ', ' encoding ' = ' utf8 ', ' prefix ' and ', ' );
Then the page will be displayed when the 404 error is reported. Finally, a workaround is found, as follows:
PHP code
/ * * Testbase Library Model * */ class Testquestion extends appmodel{public $name = ' Preschooltestquestion '; var $useDbConfig = ' testbase '; var $useTable = false; } /* * Testbase Library model * */class testquestion extends appmodel{public $name = ' preschooltestquestion '; var $useDbConfig = ' Testbase '; var $useTable = false;}
is to create a model file with the name of the table in the Wss_test library under the Models folder, and then indicate which library to use.
By the way: if the default library has this table, you can not use the model file description. such as in the master-slave library can be so Loadmodel (' testquestion '), and then $this->testquestion->usedbconfig = ' testbase ';
That's what cakephp calls the data tables in different databases, and more about topic.alibabacloud.com (www.php.cn)!