如何在mysql查询中转义一个点?(How to escape a dot in mysql query?)

编程入门 行业动态 更新时间:2024-10-28 08:24:45
如何在mysql查询中转义一个点?(How to escape a dot in mysql query?)

数组$ rf的值包含一个点:

$rf = array(img34563.jpg , img34536.jpg); $query = "SELECT * FROM $appin_table WHERE img IN ( ".implode( ',' , $rf ).""; $result = mysql_query($query) or die(mysql_error());

我怎么能逃脱这个点,这可能吗?

提前致谢。

The values of the array $rf contain a dot:

$rf = array(img34563.jpg , img34536.jpg); $query = "SELECT * FROM $appin_table WHERE img IN ( ".implode( ',' , $rf ).""; $result = mysql_query($query) or die(mysql_error());

How could I escape the dot, is that possible?

Thanks in advance.

最满意答案

单独逃离点对你没有帮助; 你会得到这样的查询:

SELECT * FROM table WHERE img IN(img34563.jpg , img34536.jpg)

您必须先申请报价:

function quote($k) { return '"' . mysql_real_escape_string($k) . '"'; } $values = array_map('quote', $rf); $query = "SELECT * FROM $appin_table WHERE img IN ( ".implode( ',' , $values )."";

Escaping the dot alone won't help you; you'll end up with a query like that:

SELECT * FROM table WHERE img IN(img34563.jpg , img34536.jpg)

You'll have to apply quotes before:

function quote($k) { return '"' . mysql_real_escape_string($k) . '"'; } $values = array_map('quote', $rf); $query = "SELECT * FROM $appin_table WHERE img IN ( ".implode( ',' , $values )."";

更多推荐

本文发布于:2023-07-28 21:52:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1309463.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何在   mysql   escape   dot   query

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!