
Signature
Marc Bissonnette
Looking for a new ISP? http://www.canadianisp.com
Largest ISP comparison site across Canada.
Something to sell ? http://www.pennypinchernewspaper.com
> In my script (perl):
use strict;
use warnings;
(since you have $chop $query somewhere below, I guess you don't have
those two lines?)
> use URI::Escape;
> use DBI;
[quoted text clipped - 6 lines]
> }
> chop $query;
you could have written that as:
$query .= join ',', map { "`$_`" } @allvars;
(saves you the chop to remove the ,)
> $query.=') VALUES (';
> for (@allvars) {
> if ($in{$_} eq undef) {
> $query.='NULL,';
> } else {
> $in{$_}=uri_escape($in{$_});
Why, oh why do you uri_escape this? To protect yourself against SQL
injection? Don't do this, but:
$query .=') VALUES (';
# add a place holder (?) for each value in @allvalues:
$query .= join ',', ( '?' ) x @allvalues;
> $query.=')';
> my $dbh;
[quoted text clipped - 3 lines]
> $sth=$dbh->prepare($query);
> $sth->execute();
replace with
$sth->execute( @allvalues );
> $sth->finish;
> $dbh->disconnect;
So in short (example, assuming $name and $address needs to be inserted):
my $query = 'INSERT INTO sometable ( name, address ) VALUES ( ?, ? )';
my $sth = $dbh->prepare( $query );
$sth->execute( $name, $address );
$sth->finish;
See perldoc DBI for more information. This protects you from SQL
injection. Also, note that DBI replaces undef with NULL (and vice
versa).

Signature
John Bokma http://johnbokma.com/
AISE/AWW/SEO/web development forum: http://seo-expert-wiki.com/
Marc Bissonnette - 31 Jul 2008 21:16 GMT
>
>> In my script (perl):
[quoted text clipped - 63 lines]
> injection. Also, note that DBI replaces undef with NULL (and vice
> versa).
Oh that is *very* cool - thank you very much.
I've got a fresh cup of coffee and am sitting down to do just that
(perldoc DBI)
Thanks again - I suspect this going to shrink the size of quite a few of
my db tables.

Signature
Marc Bissonnette
Looking for a new ISP? http://www.canadianisp.com
Largest ISP comparison site across Canada.
Something to sell ? http://www.pennypinchernewspaper.com