?$dbh->do(qq{INSERT INTO files (file, dev, ino, mode, nlink, uid, gid, rdev, size, atime, mtime, ctime, md5sum, bz2size, disc, newfile) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )}, undef, $filename, $dev, $ino, (sprintf "%lo", $mode), $nlink, $ui +d, $gid, $rdev, $size, $atime, $mtime, $ctime, $digest, undef, undef, undef);
I discovered recently that most DBD's allow you to use named placeholders if you use the bind_param function. Even if it's less concise, I think this is a good idea for readability and maintainability.
So instead of doing this:
You can do this:$sth = $dbh->prepare('SELECT * FROM modules WHERE module LIKE ? AN +D code LIKE ?'); $rv = $sth->execute('%v%', '%x%');
Sure, it's wordier, but you'll never count question-marks again! Plus, you can edit your SQL later; moving the placeholders won't matter.$sth = $dbh->prepare('SELECT * FROM modules WHERE module LIKE :m A +ND code LIKE :c'); $sth->bind_param(':m', "%v%"); $sth->bind_param(':c', "%x%"); $rv = $sth->execute;
Caveat... DBD:Pg seems to only allow one-character placeholders. I don't know why.
In reply to named placeholders in DBI by risacher
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |