Doesn't doing it that way preclude using $dbh->quote? That could mess up
if the name had a single quote in it.
One idea I had was to do something like this:
my ($f, $d); # form data, database data
for (qw(friendly parent intentional address port timeout priority)) {
$f{$_} = $q->param($_);
$d{$_} = $dbh->quote($f{$_});
}
$d{address} = "INET_ATON($d{address})";
$dbh->do("REPLACE INTO services SET ".
join(',', map { "$_ = $d{$_}" } keys %d));
Basically, I put all my variables into a hash, then I do some magic with
join, map and keys to automatically generate the SQL query part after SET.
If I use it a lot, the "for" loop could be replaced by a function call
that passes $f, $d and the list of variables to set.
What do you guys think of that technique?
On 16 Aug 2001, Harald Fuchs wrote:
> I'd do it like that:
>
> my $sql = q{
> REPLACE INTO services
> SET friendly = ?,
> parent = ?,
> intentional = ?,
> address = INET_ATON(?),
> port = ?,
> timeout = ?,
> priority = ?
> };
> $dbh->do ($sql, undef,
> $friendly, $parent, $intentional, $address,
> $port, $timeout, $priority);
---------------------------------------------------------------------
Before posting, please check:
http://www.mysql.com/manual.php (the manual)
http://lists.mysql.com/ (the list archive)
To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php