Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- use DBI;
- use strict;
- use warnings;
- print "Enter Username: ";
- my $user = <>;
- print "Enter Password: ";
- my $password = <>;
- my $data_source = "dbi::mysql:trial";
- my $dbh = DBI->connect($data_source, $user, $password)
- or die "Can't connect to $data_source: $DBI::errstr";
- my $sth = $dbh->prepare( q{SELECT name, phone FROM mytelbook})
- or die "Can't prepare statement: $DBI::errstr";
- my $rc = $sth->execute
- or die "Can't execute statement: $DBI::errstr";
- print "Query will return $sth->{2} fields.\n\n";
- print "Field names: @{ $sth->{NAME} }\n";
- while (($name, $phone) = $sth->fetchrow_array) {
- print "$name: $phone\n";
- }
- # check for problems which may have terminated the fetch early
- die $sth->errstr if $sth->err;
- $dbh->disconnect;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement