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

2018-07-20    来源:open-open

容器云强势上线!快速搭建集群,上万Linux镜像随意使用
<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['submit'])) {
 
     $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['dept_id'];
 
     if ($result_set = $dbh->query("call employee_list( $dept_id )")) {
          print ('<table border="1" width="30%"> <tr> '.
               '<td>Employee_id</td><td>Surname</td><td>Firstname</td></tr>');
          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();
}
?>

标签: Mysql

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点!
本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。

上一篇:PHP实现直接在页面上执行SQL语句

下一篇: Java之多线程断点下载的实现