SQL查询+特殊字符ä,ö,ü,ø等 [英] SQL Query + special characters ä, ö, ü, ø etc

查看:658
本文介绍了SQL查询+特殊字符ä,ö,ü,ø等的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在最近几天遇到了一个问题,需要一些提示来解决这个问题。

I'm wrapping my head around a problem for the last couple of days and need some tips on how to solve the problem.

我有一个sql查询看起来像这样

I have a sql query which looks like this

    mysql_real_escape_string($value);
    $sql_first = "SELECT `user_id` FROM `usermeta` WHERE `meta_value` = '".$value."'



如果$值不包含像äüöø等字符,则工作正常



数据库的排序规则为 utf8_general_ci


It works fine if $value isn't containing characters like ä ü ö ø

The collation of the database is utf8_general_ci

我尝试过各种组合 conv()函数,但不能让它工作。

I tried various combinations with the php conv() function, but can't get it to work.

我想我必须转换 $ value 到UTF-8 - 这是否正确?

I guess I have to convert $value to UTF-8 - is this going in the right direction?

推荐答案

使用准备好的语句,数据库驱动程序将为您执行一切,您不会受到SQL注入攻击作为奖励。

Use prepared statements, and the database driver will do everything for you, and you won't be subject to SQL injection attacks as a bonus.

请参阅 http://php.net/manual/fr/mysqli.prepare.php

这篇关于SQL查询+特殊字符ä,ö,ü,ø等的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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