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.


In reply to DBI, quoting, and LIKE searches by Mr_Person

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.