mysql select用hashtag替换双引号

时间:2017-05-28 19:58:40

标签: mysql mysqli mysql-workbench

我一直在阅读文档并搜索google-net,试图弄清楚如何构建一个返回varchar字段中双引号的mysql的select查询。

我发现的一切都说不首先插入引号而不是逃避它们。同意100%...但我收到了其他人的数据库。他们使用MySQL Workbench创建它...它允许他们在varchar字段中输入双引号值。我怎么能得到双引号呢? mysql客户端(命令行)和mysqli(php)都将双引号转换为哈希标记。

我可以转储数据库,手动替换所有引号,然后重新导入。但这只有在我收到此数据库的下一次交付之前才有效。

我在这里缺少什么?

(我尝试添加屏幕截图,但Imagur现在似乎并不想处理它们)...所以这里是我所看到的复制/粘贴:

在MySQL Workbench中(只是"值"字段):

If you would like to keep your responses anonymous, you may do so.  Simply click on the ”anonymous” checkbox above each ”Feedback” block.   When you submit your survey, you will be sent a link, by email, to revisit/modify your responses. Hold onto that email as that will be the only mechanism for associating you with your anonymous responses.

来自mysql客户端:

mysql> select * from survey_labels where item_id=149;
+---------+------+-------+--------+------+------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| item_id | type | level | italic | bold | size | value                                                                                                                                                                                                                                                                                                                                                    |
+---------+------+-------+--------+------+------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|     149 | text |     2 |      0 |    0 | NULL | If you would like to keep your responses anonymous, you may do so.  Simply click on the #anonymous# checkbox above each #Feedback# block.   When you submit your survey, you will be sent a link, by email, to revisit/modify your responses. Hold onto that email as that will be the only mechanism for associating you with your anonymous responses. |
+---------+------+-------+--------+------+------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.09 sec)

1 个答案:

答案 0 :(得分:1)

我会使用PHPs function htmlspecialchars()将这些特殊字符转换为html-codes

但是对于你的问题:弄清楚你的Workbench正在使用哪种编码,并使你的PHP和你的mysql客户端使用相同的。您可以在工作台的创建脚本和客户端的选项中找到它。

如果实际有双引号,也请检查该脚本。

如果没有任何结果,只需将数据库中的值更改为",因为您将使用该表99%作为前端输出,而只有1%通过工作台访问。