Connect to the mysql database using the pdo method in thinkPHP

Source: Internet
Author: User
First, find the config in the Conf sub-directory under the Common directory in the project file directory. add the following code to the PHP file: DB_TYPE & amp; gt; pdo, DB_USER & amp; gt; root, DB_PWD & amp; gt; database password, DB_PREFIX & amp; gt; think _, table prefix DB_DSN & amp; gt; mysql :... first, find the config in the Conf sub-directory under the Common directory in the project file directory. php file

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 = name of the connected database; charset = utf8'



Note: charset = UTF8 instead of the UTF-8, an error will be reported when writing the UTF-8 page.

Another method is as follows:

Model (['model name'], ['data table prefix'], ['database connection information']); the database is defined in the connection information of the third parameter database.

For example, $ user = new Model ('user', 'think _ ', 'MySQL: // root: 123456 @ localhost/thinkphp ');

Database Connection information format: Database type: // user name: password @ database address: database port/database name # Character set

This example is modified based on actual conditions.

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.