http://www.perlmonks.org?node_id=1066216


in reply to DBI and mysql query formatting

A few points, not related to the keys/values question:

Placeholders example:

my $names=join(',',keys %test); my $placeholders=join(',',('?' x scalar keys %test)); my $sth=$dbh->prepare("INSERT into test ($names) VALUES ($placeholders +)"); # no error check, assuming RaiseError => 1 in DBI->connect() $sth->execute(values %test); # again, no error check, DBI will die on +errors $sth->finish(); # no error check, DBI will handle that

Note that DBI automatically translates undef in values to NULL in the database, so you don't have to care for that. And of course, you don't have to care for correctly quoting values.

Alexander

--
Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)