Advertisement
Guest User

Untitled

a guest
Jul 27th, 2017
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. #!/usr/bin/perl
  2. use DBI;
  3. use strict;
  4. use warnings;
  5. print "Enter Username: ";
  6. my $user = <>;
  7. print "Enter Password: ";
  8. my $password = <>;
  9.  
  10. my $data_source = "dbi::mysql:trial";
  11. my $dbh = DBI->connect($data_source, $user, $password)
  12. or die "Can't connect to $data_source: $DBI::errstr";
  13. my $sth = $dbh->prepare( q{SELECT name, phone FROM mytelbook})
  14. or die "Can't prepare statement: $DBI::errstr";
  15. my $rc = $sth->execute
  16. or die "Can't execute statement: $DBI::errstr";
  17. print "Query will return $sth->{2} fields.\n\n";
  18. print "Field names: @{ $sth->{NAME} }\n";
  19. while (($name, $phone) = $sth->fetchrow_array) {
  20. print "$name: $phone\n";
  21. }
  22. # check for problems which may have terminated the fetch early
  23. die $sth->errstr if $sth->err;
  24. $dbh->disconnect;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement