Connect to mysql database through pdo method in thinkPHP

巴扎黑
Release: 2016-11-08 10:22:13
Original
1004 people have browsed it

First find the config.php file in the Conf subdirectory of the Common directory in the project file 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, and an error will be reported when writing UTF-8 web pages.

There is another method: for model instantiation using Model(), you can use the third part of:

Model(['Model name'], ['Data table prefix'], ['Database connection information']); Define the database in each parameter database connection information

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

The format of the database connection information is: database Type://username:password@database address:database port/database name#Character set

This example should be modified according to the actual situation


Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!