PHP Framework-thinkphp M model table prefixes when to use the $tablePrefix, when to use ' Db_prefix '?

Source: Internet
Author: User
Tags php framework
I know there are two ways to define table prefixes when creating M-models,
One is in $tablePrefix one is defined in the $connection,

Why do I use it here?

protected $connection = array    (        'DB_TYPE' => 'mysql',    //数据库类型        'DB_USER' => 'root',    //用户名        'DB_PWD'  => '',    //密码        'DB_HOST' => 'localhost',    //域名        'DB_PORT' => '3306',    //??        'DB_NAME' => 'minute1',    //库名        'DB_CHARSET' => 'UTF8',    //编码        'DB_PREFIX' => 'minute1_'    //★★★★★★★★★★★★数据库表前缀minute1_    );

No, but the use of protected $tablePrefix = "Minute1_" is good, please tell me when to use which kind of?

Reply content:

I know there are two ways to define table prefixes when creating M-models,
One is in $tablePrefix one is defined in the $connection,

Why do I use it here?

protected $connection = array    (        'DB_TYPE' => 'mysql',    //数据库类型        'DB_USER' => 'root',    //用户名        'DB_PWD'  => '',    //密码        'DB_HOST' => 'localhost',    //域名        'DB_PORT' => '3306',    //??        'DB_NAME' => 'minute1',    //库名        'DB_CHARSET' => 'UTF8',    //编码        'DB_PREFIX' => 'minute1_'    //★★★★★★★★★★★★数据库表前缀minute1_    );

No, but the use of protected $tablePrefix = "Minute1_" is good, please tell me when to use which kind of?

$tablePrefix is defined in the model, the priority is greater than the configuration file, the use of the case is generally your project in the initial table prefix all such as "A_", you defined in the configuration file

'DB_PREFIX'=>'a_'

But after adding a b_temp table, this time to instantiate the temp if not processed, the system will look for a_temp, this table does not exist, this time need to define in the temp model $tableprefix= ' b_ ';

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