PHP调用MySQL存储过程并获得返回值的代码
时间:2021-07-01 10:21:17
帮助过:29人阅读
Employee listing
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 ('
'.- '
Employee_id | Surname | Firstname | ');- while ($row = $result_set->fetch_object()) {
- printf("
%s | %s | %s | \n", - $row->employee_id, $row->surname, $row->firstname);
- }
- } else {
- printf("
Error:%d (%s) %s\n", mysqli_errno($dbh), - mysqli_sqlstate($dbh), mysqli_error($dbh));
- }
- print ("
"); - $dbh->close();
- }
- ?>
|