PHP Framework-thinkphp These two ways of configuring M, what is the difference?

Source: Internet
Author: User
Tags php framework
//第一种,在 *Model.class.php:protected $dbName = 'ybdbshop';    //库名,也可以从配置文件,或者 D() 参数设置;protected $tableName = 'abc';    //不加前缀的表名,也可以从类名设计;protected $tablePrefix="";    //表前缀;
//第二种:protected $connection = array(    'DB_TYPE' => 'mysql',    'DB_USER' => 'root',    'DB_PWD'  => '',    'DB_HOST' => 'localhost',    'DB_PORT' => '3306',    'DB_NAME' => 'ybdbcjd',    //库名    'DB_CHARSET' =>    'UTF8',);

What's the difference between these two?
Why does the first kind of me sometimes use no mistakes, and I copy the whole project to another computer?

Reply content:

//第一种,在 *Model.class.php:protected $dbName = 'ybdbshop';    //库名,也可以从配置文件,或者 D() 参数设置;protected $tableName = 'abc';    //不加前缀的表名,也可以从类名设计;protected $tablePrefix="";    //表前缀;
//第二种:protected $connection = array(    'DB_TYPE' => 'mysql',    'DB_USER' => 'root',    'DB_PWD'  => '',    'DB_HOST' => 'localhost',    'DB_PORT' => '3306',    'DB_NAME' => 'ybdbcjd',    //库名    'DB_CHARSET' =>    'UTF8',);

What's the difference between these two?
Why does the first kind of me sometimes use no mistakes, and I copy the whole project to another computer?

I have answered this question just now.

class classoneModel extends Model{    protected $dbName = 'ybdbcjd'; }

What's in $dbName it.
It is used to operate a different database under the same MySQL account, if you do have this database in the same MySQL account, and have the appropriate permissions, it can be executed correctly. The resulting SQL-like statement is:

select * from ybdbcjd.table

This is not thinkphp its own sense of the switch database, but mysql its own cross-database operation syntax, the limitations are large, is not recommended to use.
is to manipulate other databases in the context of the current database.

use db1select * from db2.table

But the second kind of direct modification $connection is to switch the database connection.
is to operate another database under another database.

use db2select * from tablez

The difference is right here.
If it is a small number of operations can cross the database, or directly create a new database connection.

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