Heim  >  Artikel  >  Backend-Entwicklung  >  PHP 调用 MySQL 存储过程并获得返回值的代码

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

WBOY
WBOYOriginal
2016-07-25 08:52:01761Durchsuche
  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. ?>
复制代码


Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn