TP5.1: Connection Database (global configuration, dynamic configuration, DSN configuration)

Source: Internet
Author: User
Tags dsn

Premise:

(1) Create a new controller file named connect.php under the App\index\controller file

(2) Create a database named User_curd, which has a user table with the following table:

  

  Connect to a database with global configuration ( recommended )

1. Open the global configuration file: think\config\databases.php

2, enter in the connect.php:

  

Enter the URL: localhost/tp5 the installation directory/think/public/index.php/index/connect/connect, the result is:

  

  Connecting databases with dynamic configuration

1, open the global configuration, the relevant information to comment out

 

2. Enter in connect.php

  

3. Results:

  

  Using DSN configuration to connect to a database

1, open the global configuration, the relevant information to comment out


2, enter in the connect.php:

Results:

Above

END

  

TP5.1: Connection Database (global configuration, dynamic configuration, DSN configuration)

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.