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

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

PHP中文网
Release: 2016-05-25 17:16:09
Original
1131 people have browsed it
跳至            
<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();
}
?>
Copy after login



source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template