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

What to do if php pdo mysql is garbled

藏色散人
Release: 2023-03-11 12:12:01
Original
2033 people have browsed it

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);
Copy after login

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!

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