PERL   17

DB perl

Guest on 7th June 2022 01:14:37 AM

  1. #!/usr/bin/perl -w
  2. use DBI;
  3. print "Content-Type: text/plain", "\n\n";
  4. ## user database name
  5. $db ="mysql";
  6. ## database user name
  7. $user = "root";
  8. ## database password
  9. $pass = "root";
  10.  
  11. ## user hostname : This should be "127.0.0.1"
  12. ## if you want to use localhost copy /etc/hosts file to
  13. ## /webroot/etc directory
  14. ##
  15. $host="127.0.0.1";
  16.  
  17. ## SQL query
  18. $query = "show tables";
  19.  
  20. $dbh = DBI->connect("DBI:mysql:$db:$host", $user, $pass);
  21. $sth = $dbh->prepare($query) or die "Can't prepare $query: $dbh->errstr\n";
  22.  
  23. $rv = $sth->execute or die "can't execute the query: $sth->errstr";
  24.  
  25. print "<h1>Perl DBI Test</h1>";
  26. print "<p>Here is a list of tables in the database $db.</p>";
  27. while (@row= $sth->fetchrow_array()) {
  28. my $tables = $row[0];
  29. print "$tables\n<br>";
  30. }
  31.  
  32. #$rc = $sth->finish;
  33. exit(0);

Raw Paste


Login or Register to edit or fork this paste. It's free.