Mr_Person has asked for the wisdom of the Perl Monks concerning the following question:
What is the best way to construct a LIKE search with DBI? I know that I should always use $dbi->quote or a placeholder to keep the search string from messing up my SQL statement (the search string will be entered by a user on a webpage), and I have read that using a placeholder in this case can cause performance problems. However, using $dbi->quote on a search string like "%foo%" (where "foo" is the string entered by the user on the webpage and %'s are added by the program) will quote out the %'s. I also can't just put %'s on the outsides of the quoted string, because the quote function adds in quotes, so that would give me "%'foo'%". In the past, I've used $dbi->quote on the search string without the %'s, then used a regex to add a % after the first ' and before the last ' in the string. Certainly there's a better way!
Thanks,
Curtis H.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: DBI, quoting, and LIKE searches (no good answer)
by tye (Sage) on Dec 26, 2002 at 17:33 UTC | |
|
Re: DBI, quoting, and LIKE searches
by pfaut (Priest) on Dec 26, 2002 at 17:06 UTC | |
by Anonymous Monk on Dec 26, 2002 at 17:21 UTC | |
by tye (Sage) on Dec 26, 2002 at 17:36 UTC | |
by Mr_Person (Hermit) on Dec 26, 2002 at 17:41 UTC | |
by Ryszard (Priest) on Dec 27, 2002 at 16:42 UTC | |
| |
|
Re: DBI, quoting, and LIKE searches
by dws (Chancellor) on Dec 26, 2002 at 19:52 UTC | |
|
Re: DBI, quoting, and LIKE searches
by Three (Pilgrim) on Dec 27, 2002 at 14:18 UTC |