#!/usr/bin/perl -w use DBI; use strict; my $dbh = DBI->connect("DBI:mysql:test;host=localhost" . ";mysql_read_default_file=$ENV{HOME}/.my.cnf", undef, undef, {RaiseError => 1}) or die "can't connect\n"; my $pairs = { ONE => 'RTEST', TWO => undef, THREE => 'ANOTHER' }; # Creating a dummy table to match the example $dbh->do(qq{CREATE TABLE IF NOT EXISTS web_sessions_aux (wsa_id INT not null, wsa_type char(10), wsa_key char(10), wsa_value char(10))}); my ($id,$type) = (1,'UNKNOWN'); my $sth = $dbh->prepare(" INSERT INTO web_sessions_aux (wsa_id, wsa_type, wsa_key, wsa_value) VALUES (?,?,?,?)"); DBI->trace(2); foreach my $key (keys %$pairs) { my $key_value = defined($pairs->{$key})? $pairs->{$key} : ''; $sth->execute($id,$type,$key,$key_value); } DBI->trace(0); $dbh->disconnect(); #### DBI 1.21-nothread dispatch trace level set to 2 -> execute for DBD::mysql::st (DBI::st=HASH(0x81342c0)~0x80b1264 1 'UNKNOWN' 'TWO' '') -> dbd_st_execute for 081342f0 Binding parameters: INSERT INTO web_sessions_aux (wsa_id, wsa_type, wsa_key, wsa_value) VALUES (1,'UNKNOWN','TWO','') <- dbd_st_execute 1 rows <- execute= 1 at dbi_quoting_problem.pl line 29 -> execute for DBD::mysql::st (DBI::st=HASH(0x81342c0)~0x80b1264 1 'UNKNOWN' 'THREE' 'ANOTHER') -> dbd_st_execute for 081342f0 Binding parameters: INSERT INTO web_sessions_aux (wsa_id, wsa_type, wsa_key, wsa_value) VALUES (1,'UNKNOWN','THREE','ANOTHER') <- dbd_st_execute 1 rows <- execute= 1 at dbi_quoting_problem.pl line 29 -> execute for DBD::mysql::st (DBI::st=HASH(0x81342c0)~0x80b1264 1 'UNKNOWN' 'ONE' 'RTEST') -> dbd_st_execute for 081342f0 Binding parameters: INSERT INTO web_sessions_aux (wsa_id, wsa_type, wsa_key, wsa_value) VALUES (1,'UNKNOWN','ONE','RTEST') <- dbd_st_execute 1 rows <- execute= 1 at dbi_quoting_problem.pl line 29 #### _ _ _ _ (_|| | |(_|>< _|