Cody Pendant has asked for the wisdom of the Perl Monks concerning the following question:
Say I have a MySQL db that I want to search for the phrase
it's not a problem
Then I have to use something like this:
SELECT * FROM foo WHERE bar LIKE 'it's not a problem'
But of course that doesn't work.
So I try and use $dbh->quote(), which changes it to this:
SELECT * FROM foo WHERE bar LIKE 'it\'s not a problem'
But that doesn't work either.
The way to successfully search with apostrophes in a LIKE statment is
SELECT * FROM foo WHERE bar LIKE 'it''s not a problem'
So is there another quote() method I could be using to get that result? Or shall I just hope that
$str =~ s/'/''/g
Will do the trick, and I don't end up with an odd number?
($_='kkvvttuubbooppuuiiffssqqffssmmiibbddllffss')
=~y~b-v~a-z~s; print
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Quoting Strings For SQL LIKE queries
by jZed (Prior) on Dec 22, 2004 at 00:47 UTC | |
by Cody Pendant (Prior) on Dec 22, 2004 at 01:01 UTC | |
by jZed (Prior) on Dec 22, 2004 at 01:07 UTC | |
by Cody Pendant (Prior) on Dec 22, 2004 at 01:27 UTC | |
by jZed (Prior) on Dec 22, 2004 at 01:35 UTC | |
| |
by tye (Sage) on Dec 22, 2004 at 06:32 UTC | |
|
Re: Quoting Strings For SQL LIKE queries
by aquarium (Curate) on Dec 22, 2004 at 04:41 UTC |