Guest User

Untitled

a guest
Jan 22nd, 2018
292
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. #!/usr/bin/perl
  2.  
  3. #use strict;
  4. #use warnings;
  5.  
  6. use DBI;
  7.  
  8. my @array = (
  9. [143, 'ri@moo.com.au', 'Richard', 5],
  10. [167, 'ri@goo.com.au', 'Mitch', 5],
  11. [173, 'ri@foo.com.au', 'Ross', 5]
  12. );
  13.  
  14. $dbh = DBI->connect('DBI:mysql:helpdesk', 'staff', 'pass'
  15. ) || die "Could not connect to database: $DBI::errstr";
  16.  
  17. for(my $i = 0; $i <= $#array; $i++){
  18.  
  19. my $total = 0;
  20. print "\n---------------\n $array[$i][1] \n--------------\n";
  21. my $sth = $dbh->prepare('SELECT hours FROM Bills WHERE entry_owner = ' . $array[$i][0] . ' AND date = date(now())')
  22. or die "Couldn't prepare statement: " . $dbh->errstr;
  23. $sth->execute
  24. or die "Couldn't execute SQL statement:" . $dbh->errstr;
  25.  
  26. while (my @row = $sth->fetchrow_array) {
  27. $total += @row;
  28. print "@row\n";
  29. }
  30.  
  31. print "Total: " . $total;
  32.  
  33.  
  34.  
  35. }
  36.  
  37. $dbh->disconnect();
Add Comment
Please, Sign In to add comment