Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $database = 'DATABASE';
- $username = 'USERNAME';
- $password = 'PASSWORD'
- try {
- $dbh = new PDO('mysql:host=localhost;dbname='.database, $username, $password);
- } catch (PDOException $d) {
- print "Error: " . $e->getMessage() . "\n";
- }
- $sth = $dbh->prepare('SELECT sum(bytes) as bytes
- FROM table
- WHERE key = :interfaceid');
- $bytes = null;
- $sth->bindColumn('bytes', $bytes);
- $interface_id = null;
- $sth->bindParam(':interfaceid', $interfaceid, PDO::PARAM_INT);
- $interface_ids = array(3, 5, 6);
- foreach($interface_ids as $interfaceid) {
- if( exec_fetch($sth) )
- print "Got $bytes\n";
- }
- function exec_fetch(&$sth) {
- try {
- $sth->execute();
- return $sth->fetch();
- } catch (PDOException $e) {
- print "Error: " . $e->getMessage() . "\n";
- return false;
- }
- }
Add Comment
Please, Sign In to add comment