thinkphp5 - thinkPHP 是不是 D() model.class 和 Controller.class 裡資料庫參數的優先順序問題.

來源:互聯網
上載者: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這個庫名ybdbchfjhfjjds,是我亂換的,按理說,應該出錯,但是居然成功了!可以正常搜尋到資料,所以說,庫沒有被覆蓋,依然是 model 的庫,
而下面的例子,首碼我寫了個qqqqqqqqqqqqq,就搜不到資料了,

請問這個什麼時候會被覆蓋,什麼時候不被覆蓋?

回複內容:

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這個庫名ybdbchfjhfjjds,是我亂換的,按理說,應該出錯,但是居然成功了!可以正常搜尋到資料,所以說,庫沒有被覆蓋,依然是 model 的庫,
而下面的例子,首碼我寫了個qqqqqqqqqqqqq,就搜不到資料了,

請問這個什麼時候會被覆蓋,什麼時候不被覆蓋?

因額為D函數只有兩個參數 第一個參數是資源地址,第二個是模型層名稱
你把mysql串連放在第三個空參數上了 當然不會生效

mysql連結參數是M函數裡面的第三個參數。。

所以沒有覆蓋不覆蓋一說

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    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.