PHP calls the MySQL stored procedure and obtains the returned value code.
- Employee listing
Php code
$ 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 ('
- '
- While ($ row = $ result_set-> fetch_object ()){
- $ Row-> employee_id, $ row-> surname, $ row-> firstname );
- Printf ("
- }
- } Else {
- Printf ("
Error: % d (% s) % s \ n ", mysqli_errno ($ dbh ),
- Mysqli_sqlstate ($ dbh), mysqli_error ($ dbh ));
- }
- Print ("
'.
Employee_id |
Surname |
Firstname |
');
% S |
% S |
% S |
\ N ",
");
- $ Dbh-> close ();
- }
- ?>
|