Home  >  Article  >  Backend Development  >  PHP code to call MySQL stored procedure and get the return value

PHP code to call MySQL stored procedure and get the return value

WBOY
WBOYOriginal
2016-07-25 08:52:01759browse
  1. Employee listing

  2. Enter Department ID:

复制代码

php代码

  1. $hostname = "localhost";

  2. $username = "root";
  3. $password = "secret";
  4. $database = "prod";

  5. if (IsSet ($_POST['submit'])) {

  6. $dbh = new mysqli($hostname, $username, $password, $database);

  7. /* check connection */

  8. if (mysqli_connect_errno()) {
  9. printf("Connect failed: %sn", mysqli_connect_error());
  10. exit ();
  11. }
  12. $dept_id = $_POST['dept_id'];

  13. if ($result_set = $dbh->query("call employee_list( $dept_id )")) {

  14. print (' '.
  15. '
  16. ');
  17. while ($row = $result_set->fetch_object()) {
  18. printf("
  19. n",
  20. $row->employee_id, $row->surname, $row->firstname);
  21. }
  22. } else {
  23. printf("

    Error:%d (%s) %sn", mysqli_errno($dbh),

  24. mysqli_sqlstate($dbh), mysqli_error($dbh));
  25. }
  26. print ("
  27. Employee_idSurnameFirstname
    %s%s%s
    ");
  28. $dbh->close();
  29. }
  30. ?>

复制代码


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn