At 09:07 AM 6/8/01 +0100, Liz Keogh wrote:
>For my own personal curiosity;
>
>Would you have to somehow protect the apostrophe in something
>like "Kelly's Trucking" before putting it into an SQL string?

I'm coming in on the middle of a thread here, but generally the best thing 
to do when working with databases in Perl is to us DBI, and if you are 
doing that, database handles have a method called quote() that will ensure 
that the value in question is properly quoted for the database you are 
using.  That way, you don't have to loose things like apostrophes.  For 
instance, omitting error checking for brevity:

my $dbh = DBI->connect("DBI:mysql:$dbname:$hostname",$dbuser,$dbpass);
my $query = "insert into foo (bar,baz) values 
(".$dbh->quote($bar).",".$dbh->quote($baz).")";
$dbh->do($query);

DBI is really cool!

Cheers,
Jeff


Reply via email to