Home > Backend Development > PHP Tutorial > thinkphp5 - Is thinkPHP an issue with the priority of database parameters in D() model.class and Controller.class?

thinkphp5 - Is thinkPHP an issue with the priority of database parameters in D() model.class and Controller.class?

WBOY
Release: 2016-07-06 13:53:54
Original
1328 people have browsed it

model:

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

Controller:

<code>public function select_()
{
    $use=D('classone','','mysql://root16656:@localhost/ybdbchfjhfjjds');
    $db=$use->select();
    echo '<pre class="brush:php;toolbar:false">';print_r($db);echo '
'; } public function select_() { $use=D('classone','qqqqqqqqqqqqqqqqqqqqqq','mysql://root16656:@localhost/ybdbchfjhfjjds'); $db=$use->select(); echo '
';print_r($db);echo '
'; }
Copy after login
Copy after login

The library name of Controller is ybdbchfjhfjjds. I changed it randomly. Logically speaking, there should be an error, but it actually succeeded! The data can be searched normally, so the library has not been overwritten and it is still the model library.
In the following example, I wrote the prefix qqqqqqqqqqqqqq, but the data cannot be found,

When will this be covered and when will it not be covered?

Reply content:

model:

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

Controller:

<code>public function select_()
{
    $use=D('classone','','mysql://root16656:@localhost/ybdbchfjhfjjds');
    $db=$use->select();
    echo '<pre class="brush:php;toolbar:false">';print_r($db);echo '
'; } public function select_() { $use=D('classone','qqqqqqqqqqqqqqqqqqqqqq','mysql://root16656:@localhost/ybdbchfjhfjjds'); $db=$use->select(); echo '
';print_r($db);echo '
'; }
Copy after login
Copy after login

The library name of Controller is ybdbchfjhfjjds. I changed it randomly. Logically speaking, there should be an error, but it actually succeeded! The data can be searched normally, so the library has not been overwritten and it is still the model library.
In the following example, I wrote the prefix qqqqqqqqqqqqqq, but the data cannot be found,

When will this be covered and when will it not be covered?

Because the D function only has two parameters, the first parameter is the resource address, and the second is the model layer name
If you put the mysql connection in the third empty parameter, of course it will not take effect

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

So there is no coverage or no coverage

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template