Posted By

markbenfield on 02/18/11


Tagged

mysql insert prepare best-practice


Versions (?)

Prepare sql in advance


 / Published in: SQL
 

  1. # --------------------------
  2. # prepare the SQL
  3. my $sqlq= "insert into interesting_interfaces ".
  4. "(datetime_created, datetime_last_update, device, interface_id, interface, auto_interesting) ".
  5. "values (now(), now(),?,?,?,?) ".
  6. "on duplicate key update datetime_last_update = now(), interface_id = ?, ".
  7. "auto_interesting=?";
  8.  
  9. my $insert = $dbh->prepare($sqlq);
  10.  
  11. $insert->execute($dev,$num,$name,$auto,$num,$auto);
  12. IF ($insert->errstr ne '')
  13. {
  14. print "$dev,$name - ($dev,$num,$name,$auto,$num,$auto) caused the following error:\n";
  15. print $insert->errstr."\n"
  16. }
  17. else { print "$dev,$name - ($dev,$num,$name,$auto,$num,$auto) successful:\n"; }
  18.  

Report this snippet  

You need to login to post a comment.