使用PHP在数据库中插入问题 [英] Problem inserting ' in DB using PHP

查看:76
本文介绍了使用PHP在数据库中插入问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我正在创建一个工具,其中PHP作为前端,SQL Server作为后端。我有一些值插入到DB中,其中包含字符(''),即单引号。


当我试图将这些值插入数据库时​​,我遇到了错误。所以我使用replace()fn用两个单引号(''')替换单个引号('')。我也成功了。值已成功插入。


但是现在问题出现在尝试从数据库中检索值时。正常的选择查询没有成功。例如:

Hi,

I am creating a tool with PHP as front end and SQL Server as back end. I have some values to be inserted into the DB which contains the character ( '' ) i.e single quote.

I had errors when i tried to insert such values into the DB. So I used the replace() fn to replace a single single quote ( '' ) by two single quotes ( '''' ). I was successful in it also. Values got inserted successfully.

But the problem now arises while trying to retrieve the values from the DB. A normal select query didn''t work out. For example:

展开 | 选择 | Wrap | 行号

推荐答案

命名数据库字段永远不是一个好主意保留字符?


尝试将名称括在反引号中(`,`)。
it is never a good idea to name DB fields with reserved characters?

try enclosing the name in backticks (`, `).


实际上该字段是一个注释字段,其中用户将给出他的意见。它还可以包含单引号(''),它是撇号字符。


所以你的意思是说我应该使用反斜杠..好吧......我会试试..
Actually the field is a comments field where the user will give his input. It can also contain the single quote( '' ) which is the apostrophe character.

So you mean to say I should use back slash.. Ok...I will try out..


你好,


您可以发布任何使用反斜杠的样品供我参考吗?


提前致谢。


Can you post any samples which use that back slashes for my reference?

Thanks in advance.


这篇关于使用PHP在数据库中插入问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆