Advertisement
Guest User

Untitled

a guest
Nov 20th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. #!/usr/bin/perl -w
  2. use strict;
  3. use warnings;
  4. use DBI;
  5. use CGI qw(:standard);
  6. use CGI::Carp qw(fatalsToBrowser);
  7. print "Content-type: text/html\n\n";
  8.  
  9. my $driver = "mysql";
  10. my $database = "demo_TESTDB";
  11. my $dsn = "DBI:$driver:$database:localhost";
  12. my $userid = "demo_testdb";
  13. my $password = "Test1";
  14.  
  15. my $dbh = DBI->connect($dsn, $userid, $password ) or die $DBI::errstr;
  16.  
  17. my $sth = $dbh->prepare("SELECT * FROM Guests");
  18. $sth->execute() or die $DBI::errstr;
  19.  
  20. my $num_rows=$sth->rows();
  21.  
  22. my $num_fields=$sth->{NUM_OF_FIELDS};
  23.  
  24. print "<h1>Query will return $num_fields fields.</h1>";
  25. print "<h1>Query will return $num_rows rows.</h1>";
  26. print "<table><tr><th>First Name</th><th>Last Name</th></tr>";
  27. my $firstname;
  28. my $lastname;
  29.  
  30. while (($firstname, $lastname) = $sth->fetchrow()) {
  31.  
  32. print "<tr> <td>$firstname</td> <td>$lastname</td>";
  33.  
  34. }
  35. print "</table>";
  36. $sth->finish();
  37. $dbh->disconnect();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement