php pdo garbled solution: first open the corresponding code file; then use the "mysql_query("set names UTF8");" method to solve the garbled problem.
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!