Calling a stored procedure in PHP and deal with the result : PHP « Procedure Function « SQL / MySQL

SQL / MySQL
1. Backup Load
2. Command MySQL
3. Cursor
4. Data Type
5. Database
6. Date Time
7. Flow Control
8. Function
9. Insert Delete Update
10. Join
11. Key
12. Math
13. Procedure Function
14. Select Clause
15. String
16. Table Index
17. Transaction
18. Trigger
19. User Permission
20. View
21. Where Clause
Microsoft Office Word 2007 Tutorial
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / C Sharp
C# / CSharp Tutorial
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
SQL / MySQL » Procedure Function » PHP 
Calling a stored procedure in PHP and deal with the result
 

<html>
<head>
<title>Employee listing</title>
</head>
<body>
<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();
}
?>
</body></html>

        
Related examples in the same category
1. Using PHP to call a stored procedure and output the result
ww__w___.___ja_v__a___2_s._c___o___m_ | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.