MySQL UTF-8字符插入问题 [英] MySQL UTF-8 Character insert issue

查看:158
本文介绍了MySQL UTF-8字符插入问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从Facebook上取得一些字符串,但我不知道字符串中的字符编码。在插入数据库表之前,我需要将这个字符串转换成utf8。获取此错误消息。



这是我的PHP代码。 / p>

  $ email =(isset($ this-> _userinfo ['email'])?$ this-> _userinfo ['电子邮件']:''); 
$ fname = $ this-> _userinfo ['first_name'];
$ lname = $ this-> _userinfo ['last_name'];
$ name = $ this-> _userinfo ['name'];

$ sql ='INSERT INTO users'
。 '(fbid,fbuid,fullname,userlevel,email,name,sirname)'
。 ''$'$'$'$'$'$$$$$$$$ $ b。$ userlevel。',''
。$ email。',
。$ fname。
。$ lname。


解决方案

你可能想看看这个问题:



检测编码和使所有的UTF-8



特别是第二个回答由 Sebastian Grinoli



他写了一个类(并提供了链接),这将正确地将Windows扩展ASCII转换为UTF8,并在必要时更正UTF8。



在UTF8土地上有一个非常方便的工具:)


I am fetching some string from facebook , but i dont know whitch encoding in string . I need to convert this string into utf8 before inserting into database table . Getting this error message.

Here is my php code.

$email = (isset($this->_userinfo['email']) ? $this->_userinfo['email'] : '');
$fname = $this->_userinfo['first_name'];
$lname = $this->_userinfo['last_name'];
$name  = $this->_userinfo['name'];

$sql = 'INSERT INTO users '
     . '(fbid, fbuid, fullname, userlevel, email, name, sirname) '
     . 'VALUES("'
     . $this->_fbid . '","'
     . $fbuid . '","'
     . $name . '","' 
     . $userlevel . '","' 
     . $email . '","' 
     . $fname . '","' 
     . $lname . '")';

解决方案

You might want to take a look at this question:

Detect encoding and make everything UTF-8

especially the second answer by Sebastian Grinoli

He wrote a class (and offers the link to it) which would correctly encode Windows Extended ASCII to UTF8 and also correct UTF8 if necessary.

A really handy tool to have when you are in the UTF8 land :)

这篇关于MySQL UTF-8字符插入问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆