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

下面是编程之家 jb51.cc 通过网络收集整理的代码片段。

编程之家小编现在分享给大家,也给大家做个参考。

<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();
}
?>

以上是编程之家(jb51.cc)为你收集整理的全部代码内容,希望文章能够帮你解决所遇到的程序开发问题。

如果觉得编程之家网站内容还不错,欢迎将编程之家网站推荐给程序员好友。

相关文章

统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...
前言 之前做了微信登录,所以总结一下微信授权登录并获取用户...
FastAdmin是我第一个接触的后台管理系统框架。FastAdmin是一...
之前公司需要一个内部的通讯软件,就叫我做一个。通讯软件嘛...
统一支付是JSAPI/NATIVE/APP各种支付场景下生成支付订单,返...