Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I use DBD::mysql quote() function without a database connection? [duplicate]

Tags:

sql

mysql

perl

I'm writing a .sql file using Perl, not writing to the mysql database directly. I need to quote the strings in that file. Looks like the $dbh-quote() method does what I want. Except that I can't figure out how to use it without a database connection. I'd make a dummy connection, but I can't seem to do this without a database running, and the machine that is going to run this cron job won't have one.

This question is similar: Perl DBI without accessing the database and the accepted answer states that "You might attempt to load the driver you need and call the function directly", which is what I would like to do, but I can't figure out how to do that.

like image 335
Stephen Ostermiller Avatar asked Aug 19 '12 23:08

Stephen Ostermiller


2 Answers

Reliable quoting requires that the driver understand the character set/collation of the connection as escaping varies based on that information.

This is why in PHP mysql_escape_string() was replaced with mysql_real_escape_string(), which uses the database connection properties to properly escape input strings.

like image 87
Justin Swanhart Avatar answered Nov 03 '22 22:11

Justin Swanhart


Sounds like you're going to have to figure out what quote does and implement it yourself. Not having access to a real DB connection is likely going to be a show-stopper.

like image 35
Cody Caughlan Avatar answered Nov 03 '22 22:11

Cody Caughlan