php mysql insert into utf-8 [closed]

2020-02-08 04:10发布

I'm going to insert into some articles in mysql using PHP.

This is phpMyAdmin information:

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

but the data in the mysql is still like

più freddi

How do I show the data correctly?

3条回答
兄弟一词,经得起流年.
2楼-- · 2020-02-08 04:59

Get rid of the hyphen. It should be:

mysql_query("SET NAMES utf8");
查看更多
仙女界的扛把子
3楼-- · 2020-02-08 05:00

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" />
查看更多
姐就是有狂的资本
4楼-- · 2020-02-08 05:02

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

查看更多
登录 后发表回答