PHP:查询函数erron执行更新查询字符串

时间:2012-07-05 09:09:57

标签: php mysql

我的查询有问题。此查询适用于phpMyAdmin,但是当PHP执行此查询时出错。可能是什么原因?

我的PHP代码是:

var_dump($sql);
query($sql); 

我调试时:

这是查询字符串:

 UPDATE searchcolumnsets SET name = "Project X",jsonfields = "[{\"name\":\"cm:contentPropertyName\",\"title\":\"Thumbnailed Content Property Name\",\"description\":\"\",\"datatype\":\"\"},{\"name\":\"cm:defaultHomeFolderPath\",\"title\":\"Percorso cartella homepage\",\"description\":\"\",\"datatype\":\"\"},{\"name\":\"trx:enabled\",\"title\":\"Abilitato\",\"description\":\"\",\"datatype\":\"\"},{\"name\":\"cm:identifier\",\"title\":\"Identificativo\",\"description\":\"\",\"datatype\":\"\"},{\"name\":\"cm:expiryDate\",\"title\":\"Data di scadenza\",\"description\":\"Data di scadenza\",\"datatype\":\"d:date\"},{\"name\":\"cm:hits\",\"title\":\"Conteggio\",\"description\":\"Conteggio\",\"datatype\":\"d:int\"}]" WHERE id = 50

这是错误:

  

您的SQL语法有错误;查看与您的MySQL服务器版本对应的手册,以便在'name'附近使用正确的语法:“cm:contentPropertyName”,“title”:“Thumbnailed Content Property Name”,“desc”在第1行

1 个答案:

答案 0 :(得分:1)

您可以使用单引号代替。 试试这个

UPDATE searchcolumnsets SET name = 'Project X',jsonfields = '[{\"name\":\"cm:contentPropertyName\",\"title\":\"Thumbnailed Content Property Name\",\"description\":\"\",\"datatype\":\"\"},{\"name\":\"cm:defaultHomeFolderPath\",\"title\":\"Percorso cartella homepage\",\"description\":\"\",\"datatype\":\"\"},{\"name\":\"trx:enabled\",\"title\":\"Abilitato\",\"description\":\"\",\"datatype\":\"\"},{\"name\":\"cm:identifier\",\"title\":\"Identificativo\",\"description\":\"\",\"datatype\":\"\"},{\"name\":\"cm:expiryDate\",\"title\":\"Data di scadenza\",\"description\":\"Data di scadenza\",\"datatype\":\"d:date\"},{\"name\":\"cm:hits\",\"title\":\"Conteggio\",\"description\":\"Conteggio\",\"datatype\":\"d:int\"}]' WHERE id = 50