thinkphp Configuring Connection Database tips, thinkphp database tips _php Tutorials

Source: Internet
Author: User

thinkphp Configuration Connection Database tips, thinkphp database tips


In this paper, we describe the common methods of thinkphp Configuration connection database, and share them for your reference. Here's how:

1. Add database configuration information to config.inc.php in the same directory as the thinkphp portal file
Copy the Code code as follows: <?php
Return Array (
' Db_type ' = ' mysqli ',
' db_host ' = ' localhost ',
' Db_name ' + ' demo ',
' Db_user ' = ' root ',
' Db_pwd ' = ' root ',
' Db_prefix ' = ' think_ ',
);
?>
Then add the following code to the config.php file in the project directory:
Copy the Code code as follows: <?php
$arr 1=array (
' Config item ' = ' config value '
' Url_model ' =>2,
' App_debug ' =>true,
' Log_record ' =>true,
......
);
$arr 2=include ' config.inc.php ';
Return Array_merge ($arr 1, $arr 2);
?>
In the background file can also be added as the code, so that after the database configuration of the connection information changes, only need to modify the information in the config.inc.php file can be achieved at the same time to modify the foreground and background database connection configuration information.

2. If you want to connect to another database in the controller , you can do so by adding the following code:
Copy the Code code as follows: $arrr =array (
' DBMS ' = ' mysqli ',//Note that the key names in this book group are not subject to change.
' username ' = ' Google ',
' Password ' = ' Hello ',
' Hostname ' = ' 127.0.0.1 ',
' Database ' = ' mydbname ',
);
$DB =new db ($ARRR);

It is hoped that this article will be helpful to everyone's thinkphp framework design.

http://www.bkjia.com/PHPjc/920609.html www.bkjia.com true http://www.bkjia.com/PHPjc/920609.html techarticle thinkphp Configuration Connection Database tips, thinkphp Database Tips This paper describes the thinkphp Configuration connection database common methods, share to everyone for your reference. The specific method is as follows: ...

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