This article describes in detail how to call and execute the mysql stored procedure in php and then return the value returned by the stored procedure. For more information, see. method of calling the stored procedure. a. If the stored procedure has the ININOUT parameter, declare a variable... this article describes in detail how to call and execute the mysql stored procedure in php and then return the value returned by the stored procedure. For more information, see.
Method of calling the stored procedure.
A. If the stored procedure has an IN/INOUT parameter, declare a variable and input the parameter to the stored procedure. the variable is a pair of php variables, which are not required, there is no way to perform Dynamic Input, a Mysql variable.
B. If there is an OUT variable in the stored procedure, declare a Mysql variable. the declaration of the mysql variable is special. you must let the mysql server know the existence of the variable, that is, execute a mysql statement, input set @ mysqlvar = $ phpvar;
C. Use mysql_query ()/mysql_db_query () to execute the mysql variable declaration statement.
The code is as follows:Mysql_query ("set @ mysqlvar [= $ pbpvar ]");
IN this way, there is a variable IN the mysql server, @ mysqlar. if the IN parameter is used, the value of phpar can be passed IN.
For example, using the mysqli function instance, we can first create a stored procedure in mysql, the code is as follows:
mysql> delimiter // mysql> CREATE PROCEDURE employee_list (OUT param1 INT) -> BEGIN -> SELECT COUNT(*) INTO param1 FROM t; -> END -> // Query OK, 0 rows affected (0.00 sec)
Write the following code in php:
Employee listing
Query ("call employee_list ($ dept_id)") {print ('Error: % d (% s) % sn ", mysqli_errno ($ dbh), mysqli_sqlstate ($ dbh), mysqli_error ($ dbh);} print ("
'.'
Employee_id |
Surname |
Firstname |
'); // Open source code phprm.com while ($ row = $ result_set-> fetch_object () {printf ("
% S |
% S |
% S |
N ", $ row-> employee_id, $ row-> surname, $ row-> firstname) ;}} else {printf ("
"); $ Dbh-> close ();}
The core code is as follows:
$ Result_set = $ dbh-> query ("call employee_list ($ dept_id )")
Here, the employee_list is our mysql stored procedure.
Address:
Reprinted at will, but please attach the article address :-)