Guest User

Untitled

a guest
Apr 19th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. <?php
  2.  
  3. $database = 'DATABASE';
  4. $username = 'USERNAME';
  5. $password = 'PASSWORD'
  6.  
  7. try {
  8. $dbh = new PDO('mysql:host=localhost;dbname='.database, $username, $password);
  9. } catch (PDOException $d) {
  10. print "Error: " . $e->getMessage() . "\n";
  11. }
  12.  
  13. $sth = $dbh->prepare('SELECT sum(bytes) as bytes
  14. FROM table
  15. WHERE key = :interfaceid');
  16.  
  17. $bytes = null;
  18. $sth->bindColumn('bytes', $bytes);
  19.  
  20. $interface_id = null;
  21. $sth->bindParam(':interfaceid', $interfaceid, PDO::PARAM_INT);
  22.  
  23. $interface_ids = array(3, 5, 6);
  24.  
  25. foreach($interface_ids as $interfaceid) {
  26. if( exec_fetch($sth) )
  27. print "Got $bytes\n";
  28. }
  29.  
  30.  
  31. function exec_fetch(&$sth) {
  32. try {
  33. $sth->execute();
  34. return $sth->fetch();
  35. } catch (PDOException $e) {
  36. print "Error: " . $e->getMessage() . "\n";
  37. return false;
  38. }
  39. }
Add Comment
Please, Sign In to add comment