php mysql 插入 utf-8
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4663255/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
php mysql insert into utf-8
提问by yuli chika
I'm going to insert into some articles in mysql using PHP.
我将使用 PHP 在 mysql 中插入一些文章。
This is phpMyAdmin information:
这是 phpMyAdmin 信息:
Server: localhost via TCP/IP
Server version: 5.0.85-community-nt
Protocol version: 10
User: root@localhost
MySQL charset: UTF-8 Unicode (utf8)
Here is my table information:
这是我的表信息:
Table Action Records 1 Type Collation Size Overhead
article 10 InnoDB utf8_unicode_ci 16.0 KiB -
1 table(s) Sum 10 InnoDB utf8_unicode_ci 16.0 KiB 0 B
I add
我加
<?php header('Content-type:text/html; charset=utf-8'); ?>
in the top of my php code, add mysql_query("set names 'utf-8'");
before mysql_select_db("data",$db1);
在我的 php 代码顶部,添加mysql_query("set names 'utf-8'");
之前mysql_select_db("data",$db1);
but the data in the mysql is still like
但是mysql里面的数据还是像
pi?1 freddi
How do I show the data correctly?
如何正确显示数据?
回答by Imran Omar Bukhsh
Get rid of the hyphen. It should be:
去掉连字符。它应该是:
mysql_query("SET NAMES utf8");
回答by shihabudheen
Use following code for inserting
使用以下代码插入
mysql_query("SET character_set_results = 'utf8', character_set_client = 'utf8', character_set_connection = 'utf8', character_set_database = 'utf8', character_set_server = 'utf8'");
mysql_query($qry);
This is worked fine in my case
这在我的情况下工作正常
回答by Aston
You have to specify the character encoding on the client as well, use
您还必须在客户端上指定字符编码,请使用
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />