如何在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 )."";更多推荐
发布评论