首页 > php教程 > PHP源码 > PHP 调用 MySQL 存储过程并获得返回值

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

PHP中文网
发布: 2016-05-25 17:16:09
原创
1171 人浏览过
跳至            

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

<h1>Employee listing</h1>

<form method="post" >

<p>Enter Department ID:

<input type="text" name="dept_id" size="4">

<input type="submit" name="submit" value="submit"><p>

</form>

 

<?php

$hostname = "localhost";

$username = "root";

$password = "secret";

$database = "prod";

 

if (IsSet ($_POST[&#39;submit&#39;])) {

 

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

 

     /* check connection */

     if (mysqli_connect_errno()) {

          printf("Connect failed: %s\n", mysqli_connect_error());

          exit ();

     }

     $dept_id = $_POST[&#39;dept_id&#39;];

 

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

          print (&#39;<table border="1" width="30%"> <tr> &#39;.

               &#39;<td>Employee_id</td><td>Surname</td><td>Firstname</td></tr>&#39;);

          while ($row = $result_set->fetch_object()) {

               printf("<tr><td>%s</td><td>%s</td><td>%s</td></tr>\n",

                      $row->employee_id, $row->surname, $row->firstname);

          }

     } else {

          printf("<p>Error:%d (%s) %s\n", mysqli_errno($dbh),

                 mysqli_sqlstate($dbh), mysqli_error($dbh));

     }

     print ("</table> ");

     $dbh->close();

}

?>

登录后复制



本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
作者最新文章
最新问题
热门推荐
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板