How to set encoding in php sql

藏色散人
Release: 2023-03-05 06:10:01
Original
2528 people have browsed it

php sql setting encoding method: first connect to the database through the "mysql_connect" method; then use the "mysql_query("set names utf8");" method to set the encoding method to "utf8".

How to set encoding in php sql

Recommended: "PHP Video Tutorial"

PHP Set the encoding method when connecting to the Mysql database (the cause of garbled characters One)

Directly upload the code:

Connect to the database:

<?php
   $connect=mysql_connect("服务器","登录的用户名","登录的密码");  
   mysql_select_db("数据库名",$connect);
   mysql_query("set names utf8");   //这里设置编码方式为 utf8 
?>
Copy after login

ps: When I set the encoding method, I wrote mysql_query("set names utf-8") ; When I use wamp encoding locally, there is no problem with the display. Then when I put the system I made on the virtual host of Wanwang, garbled characters appear. Some Chinese characters can be displayed, and some Chinese characters are not?

and other weird characters, I checked that the encoding method of the PHP web page file and the source code are both utf-8. Finally, I found that it was a problem when setting the encoding for the database connection. I struggled with it for a long time. ........

The above is the detailed content of How to set encoding in php sql. 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