4

我目前正在将 mysql 数据库的 xml 导出导入 websql 数据库,以用于在线移动体验。

一切正常,花花公子,直到我插入的任何字符串中都有双引号。通常,在 PHP 中,我会在插入时使用类似:mysql_real_escape_string。

我知道我可以尝试的选项是编写正则表达式并制作用于添加/删除斜杠的函数。谷歌上有很多例子 - 但我希望看到的是其他人是否遇到过这个问题,并且可能有更好的解决方案。

谢谢你的帮助!

4

2 回答 2

6

Forget about escaping. Do the right thing: use placeholders. In this case data will never ever be treated as anything but raw data string. In Web SQL this can be done with executeSql. See pre-processing section on explanation on how this works.

Example straight from intro of document:

db.readTransaction(function (t) {
  t.executeSql('SELECT title, author FROM docs WHERE id=?', [id], function (t, data) {
    report(data.rows[0].title, data.rows[0].author);
  });
});

No matter what is in id variable, this request will look for verbatim value, never being interpreted as part of command.

于 2012-07-29T16:55:16.030 回答
0

一个简单的解决方法是使用 AJAX 请求将 XML 字符串发送到 PHP,PHP 将返回带有转义引号的字符串。

于 2012-07-29T16:45:29.697 回答