Connect MySQL database via PDO method in thinkphp

Source: Internet
Author: User
First locate the config.php file under the Conf subdirectory in the common directory in the project files directory

Add the following code:
' Db_type ' = ' PDO ',
' Db_user ' = ' root ',
' Db_pwd ' = ' database password ',
' Db_prefix ' = ' think_ ', table prefix
' Db_dsn ' = ' mysql:host=localhost;dbname= connected database name; Charset=utf8 '



Note: Charset=utf8 instead of UTF-8, write UTF-8 page will error.

There is one more way: for instantiating with model () models, you can:

Model ([' model name '],[' data table prefix '],[' database connection information '); The third parameter defines a database in the database connection information

such as: $user = new Model (' User ', ' think_ ', ' mysql://root:123456@localhost/thinkphp ');

The database connection Information format is: Database type://user name: password @ Database address: Database port/Database name # Character Set

This example corresponds to the actual change

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