Home > Backend Development > PHP Tutorial > Connect to mysql database through pdo method in thinkPHP

Connect to mysql database through pdo method in thinkPHP

WBOY
Release: 2016-07-28 08:25:29
Original
1096 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. Writing UTF-8 web pages will result in an error.

There is another method: for model instantiation using Model(), you can do it in:

Model(['Model name'], ['Data table prefix'], ['Database connection information']); Define the database in the three parameters 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

The above introduces how to connect to the mysql database through the pdo method in thinkPHP, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
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