通常如何在数据库中搜索可能有斜杠应用于引号的文本? [英] how does one normally search for text in a database that might have slashes applied to quotes?

查看:47
本文介绍了通常如何在数据库中搜索可能有斜杠应用于引号的文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一位用户写下这句话:这是新都市主义者的噩梦。

sprawl run amok。


他们输入了并且我的PHP脚本使用addslashes()然后

将其放入数据库中。在Urbanist的引号中,可能会在

前面插入斜杠。


稍后用户运行数据库搜索New Urbanist's

噩梦。


即使我使用LIKE运行此查询,也不会有任何回复?


我应该在运行搜索之前用addslashes点击文本吗?


大多数编码人员如何处理这个?

A user writes this sentence: "It was the New Urbanist''s nightmare of
sprawl run amok."

They input that and my PHP script hits it with addslashes() and then
the sentence gets put in the database. A slash is likely inserted in
front of the quote mark in "Urbanist''s".

Later the user runs a search of the database for "New Urbanist''s
nightmare".

Even if I run this query using LIKE, nothing will come back?

Should I hit the text with addslashes before I run the search?

How do most coders handle this?

推荐答案

2004年9月28日12:02:02 -0700, lk ****** @ geocities .com (劳伦斯)写道:
On 28 Sep 2004 12:02:02 -0700, lk******@geocities.com (lawrence) wrote:
一位用户写下这句话:这是新都市主义者的噩梦,无法实现蔓延。 ;

他们输入了这个,我的PHP脚本用addslashes()命中它,然后
将句子放入数据库中。在Urbanist的引用标记的前面可能插入斜线。


如果是,它应该只适用于将值填充到SQL中的数据库(一个糟糕的设计选择)。例如,MySQL。


这个想法是,这会导致原始值被插入数据库中的
- addslashes()只是为了编码它适用于

SQL语句,不应存储斜杠。如果它们是,那就是

加了太多次。

后来用户搜索数据库中的New Urbanist的
噩梦。

即使我使用LIKE运行此查询,也不会有任何回复?


只有当你通过逃避太多时间来破坏数据时才会损坏数据。

我应该在运行搜索之前使用addslashes搜索文本吗?


这取决于您的数据库。也许你愿意,但只有这样才能获得未被削减的

版本。这可能会变得更复杂,因为LIKE也可能支持
支持转义 - 所以这可能会成为特定于数据库的。

大多数编码人员如何处理这个?
A user writes this sentence: "It was the New Urbanist''s nightmare of
sprawl run amok."

They input that and my PHP script hits it with addslashes() and then
the sentence gets put in the database. A slash is likely inserted in
front of the quote mark in "Urbanist''s".
If it is, it should only be for databases that stuff values into SQL (a poor
design choice). For example, MySQL.

The idea is that this then results in the original value being inserted into
the database - the addslashes() is only to encode it as being suitable for the
SQL statement, the slashes should not be stored. If they are, it''s been
addslashed too many times.
Later the user runs a search of the database for "New Urbanist''s
nightmare".

Even if I run this query using LIKE, nothing will come back?
Only if you''ve mangled the data by escaping too many times.
Should I hit the text with addslashes before I run the search?
It depends on your database. Maybe you would, but only so that the un-slashed
version gets searched. This can get complicated further because LIKE may
support escapes as well - so this may become database specific.
How do most coders handle this?



< rant>

希望通过使用数据库或数据库抽象层来支持

占位符和绑定数据,与SQL语句分开,完全避免了整个问题,并减少了犯错的风险,让你自己开始注入SQL,并根据数据库,严重的性能

发行。

< / rant>


-

Andy Hassall /< an ** @ andyh。 co.uk> /< http://www.andyh.co.uk>

< http://www.andyhsoftware.co.uk/space>空间:磁盘使用情况分析工具



<rant>
Hopefully by using a database or database abstraction layer that supports
placeholders and binding data separately from the SQL statement, avoiding the
whole issue entirely and reducing the risk of making a mistake and leaving
yourself open to SQL injection, and depending on database, severe performance
issues.
</rant>

--
Andy Hassall / <an**@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool


lawrence schrieb:
lawrence schrieb:
稍后用户搜索数据库中的New Urbanist即使我使用LIKE运行此查询,也不会有任何回复?

我应该在运行之前使用addslashes来查看文本吗?

搜索?


是的。或者,如果您使用MySQL,请使用mysql_escape_string()。

大多数编码人员如何处理此问题?
Later the user runs a search of the database for "New Urbanist''s
nightmare".

Even if I run this query using LIKE, nothing will come back?

Should I hit the text with addslashes before I run the search?
Yes. Or if you use MySQL use mysql_escape_string().
How do most coders handle this?




有些人无法逃脱特殊字符。他们很可能会受到攻击

非常快。


问候,

Matthias



Some don''t escape the special chars. They are likely to be under attack
very fast.

Regards,
Matthias

< br>

***lawrenceescribió/ written(2004年9月28日12:02:02 -0700):
*** lawrence escribió/wrote (28 Sep 2004 12:02:02 -0700):
他们输入了我的PHP脚本并使用addslashes()然后<将句子放入数据库中。在Urbanist的引号中可能会插入斜杠。

稍​​后用户会在数据库中搜索New Urbanist的<即使我使用LIKE运行此查询,也不会有任何回复?

在运行搜索之前,我应该使用addslashes查看文本吗?
They input that and my PHP script hits it with addslashes() and then
the sentence gets put in the database. A slash is likely inserted in
front of the quote mark in "Urbanist''s".

Later the user runs a search of the database for "New Urbanist''s
nightmare".

Even if I run this query using LIKE, nothing will come back?

Should I hit the text with addslashes before I run the search?




也许我不明白你的意思,但我看不出是什么问题

是。转义引号并不会影响内容,它只是一种允许你在引用的字符串中输入引号的方法。



Maybe I don''t understand what you mean, but I can''t see what the problem
is. Escaping quotes doesn''t affect the content, it''s just a way to allow
you to type quotes inside a quoted string.


这篇关于通常如何在数据库中搜索可能有斜杠应用于引号的文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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