There are always netizens asked me, how to call the MySQL stored procedure through PHP to get the returned result set? Indeed, MySQL's stored procedures greatly facilitate programming and improve efficiency. However, for those who are still using PHP 4 can be troublesome, because PHP 4 can only call the stored procedure, but can not directly get the return result set, but with PHP 5 mysqli function will do. First, recompile PHP 5, add support for mysqli, or download the mysqli extension directly, no longer in detail. Just give me an example:
1. Create a stored procedure that lists all the tables under the test library:
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, write the test code with MYSQLI:
$mysqli = new Mysqli ("localhost", "root", "" "," Test "); if (Mysqli_connect_errno ()) { printf ("Connect failed:%sn", 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 broadly as follows:
Find TABLE:YEJR1
Find TABLE:YEJR2
"Related articles"
http://www.bkjia.com/PHPjc/446764.html www.bkjia.com true http://www.bkjia.com/PHPjc/446764.html techarticle There are always netizens asked me, how to call the MySQL stored procedure through PHP to get the returned result set? Indeed, MySQL's stored procedures greatly facilitate programming and improve efficiency. However, for ...