Whether the thinkphp5-thinkPHP is the priority of database parameters in D () model. class and Controller. class.

Source: Internet
Author: User
Model: {code...} Controller: {code...} the name of the Controller database, ybdbchfjhfjjds, is changed. it should be an error, but it succeeded! Data can be searched normally. Therefore, the database is not overwritten and the database is still the model Database. in the following example, I wrote a q... model prefix:

Class classoneModel extends Model {protected $ trueTableName = ''; // prefix + table name; protected $ dbName = 'ybdbcjd '; // database name, or from the configuration file, or D () parameter settings ;}

Controller:

public function select_(){    $use=D('classone','','mysql://root16656:@localhost/ybdbchfjhfjjds');    $db=$use->select();    echo '
';print_r($db);echo '
';}public function select_(){ $use=D('classone','qqqqqqqqqqqqqqqqqqqqqq','mysql://root16656:@localhost/ybdbchfjhfjjds'); $db=$use->select(); echo '
';print_r($db);echo '
';}

The Controller database name is ybdbchfjhfjjds. I changed it randomly. it should be an error, but it succeeded! Data can be searched normally. Therefore, the database is not overwritten and is still a model database,
In the following example, I wrote a qqqqqqqqqqqqqqqqq prefix, and I couldn't find the data,

When will it be overwritten or not?

Reply content:

Model:

Class classoneModel extends Model {protected $ trueTableName = ''; // prefix + table name; protected $ dbName = 'ybdbcjd '; // database name, or from the configuration file, or D () parameter settings ;}

Controller:

public function select_(){    $use=D('classone','','mysql://root16656:@localhost/ybdbchfjhfjjds');    $db=$use->select();    echo '
';print_r($db);echo '
';}public function select_(){ $use=D('classone','qqqqqqqqqqqqqqqqqqqqqq','mysql://root16656:@localhost/ybdbchfjhfjjds'); $db=$use->select(); echo '
';print_r($db);echo '
';}

The Controller database name is ybdbchfjhfjjds. I changed it randomly. it should be an error, but it succeeded! Data can be searched normally. Therefore, the database is not overwritten and is still a model database,
In the following example, I wrote a qqqqqqqqqqqqqqqqq prefix, and I couldn't find the data,

When will it be overwritten or not?

Because D function has only two parameters. The first parameter is the resource address, and the second parameter is the model layer name.
If you place the mysql connection on the third null parameter, it will not take effect.

The mysql link parameter is the third parameter in the M function ..

So there is no overwrite.

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.