Home  >  Article  >  Backend Development  >  What to do if php pdo mysql is garbled

What to do if php pdo mysql is garbled

藏色散人
藏色散人Original
2021-07-10 09:42:101979browse

php The solution to the garbled pdo mysql code is to add charset=utf8 to the statement when instantiating the pdo object. The statement is such as "new PDO('dblib:host=your_hostname;dbname=your_db;charset=UTF8' ”.

What to do if php pdo mysql is garbled

The operating environment of this article: windows7 system, PHP7.1 version, DELL G3 computer

What should I do if pdo mysql is garbled?

php uses PDO to query the mysql database and the result is Chinese garbled characters

The Chinese characters have become question marks

Solution:

Add in the statement when instantiating the pdo object charset=utf8

$db = new PDO('dblib:host=your_hostname;dbname=your_db;charset=UTF8', $user, $pass);

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of What to do if php pdo mysql is garbled. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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