欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

PHP 调用 MySQL 存储过程并获得返回值的代码

程序员文章站 2023-12-24 10:05:51
...
  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: %s\n", 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) %s\n", mysqli_errno($dbh),

  24. mysqli_sqlstate($dbh), mysqli_error($dbh));
  25. }
  26. print ("
  27. Employee_id Surname Firstname
    %s %s %s
    ");
  28. $dbh->close();
  29. }
  30. ?>
复制代码

上一篇:

下一篇: