Guest User

Untitled

a guest
Sep 10th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. Connect to MySQL database using Perl CGI and XAMPP
  2. #!/xampp/perl/bin/perl -w
  3.  
  4. use DBI;
  5.  
  6. print "Content-type:text/htmlrnrn";
  7.  
  8. $database = "mydb";
  9. $host = "localhost";
  10. $port = "3306";
  11. $user = "root";
  12. $pw = "";
  13.  
  14. $dsn = "dbi:mysql:$database:$host:$port";
  15.  
  16. print "Trying to connect <br />";
  17. $connect = DBI->connect($dsn, $user, $pw, {RaiseError=>1});
  18.  
  19. if (defined $connect) {
  20. print "Preparing query <br />";
  21. }
  22.  
  23. $query = "SELECT * FROM reference WHERE ID = 1742031";
  24. $query_handle = $connect->prepare($query);
  25.  
  26. $query_handle->execute();
  27.  
  28. $query_handle->bind_columns(undef, $pmid, $popu, $loc);
  29.  
  30. while($query_handle->fetch()) {
  31. print "$pmid, $popu, $loc <br />";
  32. }
  33.  
  34. > cpan
  35. cpan shell -- CPAN exploration and modules installation (v1.960001)
  36. Enter 'h' for help.
  37.  
  38. cpan[1]> install DBD::mysql
  39.  
  40. $dsn = "dbi:mysql:$database;host=$host;port=$port";
Add Comment
Please, Sign In to add comment