How can I obtain MySQLprocedure results through PHP? some netizens asked me, how can I call the MySQL stored procedure through php to get the returned result set at the same time? Indeed, the MySQL stored procedure greatly facilitates programming and improves efficiency. However, it is troublesome for those still using php 4, because php 4 can only call the stored procedure, but cannot directly obtain the returned result set. However, you can use the mysqli function of php 5. First, recompile php 5 to add support for mysqli, or directly download the extension module of mysqli. For example:
1. create a stored procedure to list all tables in the test database:
Mysql> DELIMITER // mysql> create procedure 'yejr' ()-> BEGIN-> show tables;-> END; // Query OK, 0 rows affected (0.12 sec) mysql> DELIMITER; mysql> CALL yejr (); + ---------------- + | Tables_in_test | + ------------------ + | yejr1 | yejr2 | + -------------------- +
2. use mysqli to compile the test code:
$ Mysqli = new mysqli ("localhost", "root", "", "test"); if (mysqli_connect_errno () {printf ("Connect failed: % s/n ", mysqli_connect_error (); exit () ;}$ query =" call yejr ();"; if ($ result = $ mysqli-> query ($ query) {while ($ row = $ result-> fetch_row () {printf ("find table: % s/n ", $ row [0]) ;}$ result-> close ();?>
The results are as follows:
Find table: yejr1
Find table: yejr2