首页  >  文章  >  后端开发  >  PHP 调用 MySQL 存储过程并获得返回值的代码

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

WBOY
WBOY原创
2016-07-25 08:52:01791浏览
  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. ?>
复制代码


声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn