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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

perl problems with mysql

Status
Not open for further replies.

bobbybobbertson

Programmer
Nov 9, 2001
119
0
0
US
What function do I use to prepare data that might be anything including quotes for DBI's mysql prepare and execute statements?

In other words how do I prepare the Unknown data below so that it won't screw up the "do" statement?

my $unknown_data = "this could have anything including single and double quotes";
$dbh->do("UPDATE transaction SET $colum = $unknown_data WHERE $column = '$trans_id')") or die "Couldn't update recdord : $DBI::errstr";
 
You will need to write some type of input parser for your unknown_data variable. If you will not have any variables in the unknown_data then I recommend using a substitution on the input that will replace all single quotes with \' - this would allow them to be passed by Perl to SQL as desired. By using single quotes to define unknown_data you prevent Perl from interpreting variables and quotation marks (and any other formatting characters IIRC).
 
Use DBI's built-in string quoter:
Code:
$quoted_string = $dbh->quote($unknown_data);
jaa
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top