Thinkphp5-thinkphp is not a priority issue for database parameters in D () Model.class and Controller.class.

Source: Internet
Author: User
Model

class classoneModel extends Model{    protected $trueTableName = '';    //前缀+表名;    protected $dbName = 'ybdbcjd';    //库名,也可以从配置文件,或者 D() 参数设置;}

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 '
';}

Controller This library name YBDBCHFJHFJJDS, is I change, supposedly, should be wrong, but incredibly successful! The data can be searched normally, so that the library is not covered, it is still the model library,
And the following example, prefix I wrote a qqqqqqqqqqqqq, I could not find the data,

When will this be overwritten, and when not to be overwritten?

Reply content:

Model

class classoneModel extends Model{    protected $trueTableName = '';    //前缀+表名;    protected $dbName = 'ybdbcjd';    //库名,也可以从配置文件,或者 D() 参数设置;}

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 '
';}

Controller This library name YBDBCHFJHFJJDS, is I change, supposedly, should be wrong, but incredibly successful! The data can be searched normally, so that the library is not covered, it is still the model library,
And the following example, prefix I wrote a qqqqqqqqqqqqq, I could not find the data,

When will this be overwritten, and when not to be overwritten?

Only two parameters for the D function the first parameter is the resource address, the second is the model layer name
You put the MySQL connection on the third null parameter, of course, it won't take effect.

The mysql link parameter is the third parameter inside the M function:

So no overlay does not cover one said

  • 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.