What to do if php pdo is garbled?

藏色散人
Release: 2023-03-06 22:20:02
Original
2104 people have browsed it

php pdo garbled solution: first open the corresponding code file; then use the "mysql_query("set names UTF8");" method to solve the garbled problem.

What to do if php pdo is garbled?

Recommended: "PHP Video Tutorial"

Solution to the garbled encoding problem of PHP pdo

How to solve the problem of querying Chinese garbled characters in php pdo programming? This article shares solutions to help everyone solve the garbled problem of php pdo. Friends in need can refer to it.

When php pdo queries Chinese, garbled characters appear.

Make the encoding of the php file and the encoding of the database consistent. (Mine is UTF8)

But the query was still garbled, and then I remembered that the mysql_query() function can set the encoding

Code example:

mysql_query("set names UTF8");
Copy after login

So, I used the same as above Methods. Solve the problem of Chinese garbled characters in pdo.

Code example:

$pdo = new PDO($dsn, $user, $pwd); //实例化对象 $pdo->query("set names utf8");
Copy after login


In this way, the pdo encoding problem is solved.

Summary:

php Chinese garbled problem, pdo Chinese garbled problem, mysql Chinese garbled problem, etc., they basically did not support Chinese at the beginning.

The above is the detailed content of What to do if php pdo 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
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!