Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to escape from a string

Status
Not open for further replies.

be12dune09a

Programmer
Nov 17, 2005
24
RO
how can I escape from a string a " ' " char to insert it in sql
 
sub escapeQuote
{
$class = shift;
$_ = shift;

s/^'(.*)'$/$1/;
s/\'/''/g;
s/(.*)/'$1'/;



return $_;
}
 
Seriously, placeholders are they correct way to do it - you don't need to worry about escaping ANY characters yourself if you use placeholders correctly.
 
placeholders, use placeholders

Mike

I am not inscrutable. [orientalbow]

Want great answers to your Tek-Tips questions? Have a look at faq219-2884

 
If you can't use placeholders (and, for example, Microsoft Sequel Server doesn't support them via DBD::Sybase) then use the quoting mechanism provided in the DBI library, like it says on the tin.
Code:
$quoted_string = $dbh->quote($string);

Why invent your own?

fish


["]As soon as we started programming, we found to our surprise that it wasn't as easy to get programs right as we had thought. Debugging had to be discovered. I can remember the exact instant when I realized that a large part of my life from then on was going to be spent in finding mistakes in my own programs.["]
--Maur
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top