Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Using regex to add a single backslash to escape quotes, instead of 2 backslashes or 0

by Corion (Patriarch)
on Jul 26, 2012 at 17:02 UTC ( [id://983877]=note: print w/replies, xml ) Need Help??


in reply to Using regex to add a single backslash to escape quotes, instead of 2 backslashes or 0

See the ->quote method of DBI. Do not implement this routine yourself, and even better, use DBI placeholders instead, also documented in DBI.

  • Comment on Re: Using regex to add a single backslash to escape quotes, instead of 2 backslashes or 0
  • Download Code

Replies are listed 'Best First'.
Re^2: Using regex to add a single backslash to escape quotes, instead of 2 backslashes or 0
by lancer (Scribe) on Jul 26, 2012 at 17:50 UTC
    Thanks for the suggestion, I was able to replace it with this:

    sub sql_escape { my $text = shift; $text = DBD::_::db->quote ($text); return $text; }

    Outputs: O''REILLY

    (This format works with MySQL)

      Why don't you use

      $dbh->quote(...)

      as the documentation suggests?

        I needed to convert a CSV file to SQL format (it would be later imported with phpMyAdmin). At the time of conversion there was no database to connect to, but a $dbh can be only created with a connection to a DB.

        Someone on StackOverflow suggested to use the above solution which works without a DB connection. ( http://stackoverflow.com/a/10458266 )

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://983877]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (3)
As of 2024-04-25 14:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found