Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 1.57 KB | None | 0 0
  1.  
  2. #!/usr/bin/perl
  3. use DBI;
  4. use DBD::mysql;
  5.  
  6. print "content-type:  text/html \n\n";
  7.  
  8. #Config vars
  9.  
  10. $host = "localhost";
  11. $database = "<your database>";
  12. $tablename = "employee";
  13. $user = "<your user id>";
  14. $pw = "student";
  15.  
  16. #DATA SOURCE NAME
  17. $dsn = "dbi:mysql:$database:localhost:3306";
  18.  
  19. #PERL DBI Connect
  20. $connect = DBI->connect($dsn,$user,$pw)
  21.             or die "Unable to connect $DBI:errstr\n";
  22.  
  23. $query = "Select * from employee";
  24. $query_handle = $connect->prepare($query);
  25.  
  26. #Execute the query
  27. $query_handle->execute();
  28.  
  29. #BIND Table columns to variables
  30. $query_handle->bind_columns(\$id,\$lname,\$fname,\$job);
  31.  
  32. #!/usr/bin/perl
  33. use DBI;
  34. use DBD::mysql;
  35.  
  36. print "content-type:  text/html \n\n";
  37.  
  38. #Config vars
  39.  
  40. $host = "localhost";
  41. $database = "bstudent";
  42. $tablename = "employee";
  43. $user = "bstudent";
  44. $pw = "student";
  45.  
  46. #DATA SOURCE NAME
  47. $dsn = "dbi:mysql:$database:localhost:3306";
  48.  
  49. #PERL DBI Connect
  50. $connect = DBI->connect($dsn,$user,$pw)
  51.             or die "Unable to connect $DBI:errstr\n";
  52.  
  53. $query = "Select * from employee";
  54. $query_handle = $connect->prepare($query);
  55.  
  56. #Execute the query
  57. $query_handle->execute();
  58.  
  59. #BIND Table columns to variables
  60. $query_handle->bind_columns(\$id,\$lname,\$fname,\$job);
  61. print "<html><title>Show Employees</title>";
  62. print "<body>";
  63. print "<h1>Employee List</h1>";
  64. print "<table>";
  65. #LOOP through results
  66. while($query_handle->fetch()) {
  67.         print "<tr>";
  68.         print "<td>$id</td><td>$lname</td><td>$fname</td><td>$job</td>";
  69.         print "</tr>";
  70. }
  71. print "</table>";
  72. print "</body></html>";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement