PHP calls the MySQL stored procedure and gets the return value

From , 5 Years ago, written in PHP, viewed 238 times.
URL https://pastebin.vip/view/f023559c
  1. <h1>Employee listing</h1>
  2. <form method="post" >
  3. <p>Enter Department ID:
  4. <input type="text" name="dept_id" size="4">
  5. <input type="submit" name="submit" value="submit"><p>
  6. </form>
  7.  
  8. <?php
  9. $hostname = "localhost";
  10. $username = "root";
  11. $password = "secret";
  12. $database = "prod";
  13.  
  14. if (IsSet ($_POST['submit'])) {
  15.  
  16.      $dbh = new mysqli($hostname, $username, $password, $database);
  17.  
  18.      /* check connection */
  19.      if (mysqli_connect_errno()) {
  20.           printf("Connect failed: %s\n", mysqli_connect_error());
  21.           exit ();
  22.      }
  23.      $dept_id = $_POST['dept_id'];
  24.  
  25.      if ($result_set = $dbh->query("call employee_list( $dept_id )")) {
  26.           print ('<table border="1" width="30%"> <tr> '.
  27.                '<td>Employee_id</td><td>Surname</td><td>Firstname</td></tr>');
  28.           while ($row = $result_set->fetch_object()) {
  29.                printf("<tr><td>%s</td><td>%s</td><td>%s</td></tr>\n",
  30.                       $row->employee_id, $row->surname, $row->firstname);
  31.           }
  32.      } else {
  33.           printf("<p>Error:%d (%s) %s\n", mysqli_errno($dbh),
  34.                  mysqli_sqlstate($dbh), mysqli_error($dbh));
  35.      }
  36.      print ("</table> ");
  37.      $dbh->close();
  38. }
  39. ?>
  40.  
  41.  

Reply to "PHP calls the MySQL stored procedure and gets the return value"

Here you can reply to the paste above

captcha

https://burned.cc - Burn After Reading Website