>>>>> "Jeff" == Jeff Yoak <[EMAIL PROTECTED]> writes:

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

I wouldn't say best.  Placeholders are even more cool, and require
less thinking.

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

$dbh->do("insert into foo (bar, baz) values (?, ?)", undef,
         $bar, $baz);

Does the same thing as quote, with a lot less typing!

Jeff> DBI is really cool!

Agreed.


-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<[EMAIL PROTECTED]> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!

Reply via email to