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

What to do if php pdo is garbled?

藏色散人
藏色散人Original
2020-11-02 10:39:012130browse

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");

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");


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!

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