在php中逃避单引号mysql查询

时间:2014-05-28 15:15:07

标签: php mysql sql joomla

我有以下查询:

$query = 'UPDATE #__k2_items 
          SET extra_fields=\''.$campos_extra_updated.'\' 
          WHERE id='.$item_id;

$campos_extra_updated包含以下值,在尝试转义引号之前,我可以使用其他查询进行检索:

UPDATE ikyfb_k2_items SET extra_fields = "[{"id":"2","value":"Ser mayor de edad"},
{"id":"3","value":"asdf"},{"id":"4","value":9999998},{"id":"5","value":"10"},
{"id":"6","value":"7"},{"id":"7","value":"3"},{"id":"8","value":"1"},
{"id":"9","value":"2014-05-28"},{"id":"10","value":"2014-05-30"},
{"id":"11","value":"2014-05-28"},{"id":"12","value":"2014-05-31"},{"id":"14","value":"25"},{"id":"15","value":"20"},{"id":"16","value":"Consigue descuento ahora!"},
{"id":"17","value":"123abc"}]" WHERE id=52

SET extra_fields =之后和{"id":"17","value":"123abc"}]结束时,双撇号应为单引号,以使查询生效。

我做错了什么?我也尝试使用mysql_real_escape_string,它似乎没有用。

1 个答案:

答案 0 :(得分:0)

我设法解决了以下问题:

$query = 'UPDATE #__k2_items 
          SET extra_fields=\''.mysql_real_escape_string($campos_extra_updated).'\' 
          WHERE id='.$item_id;