Created
May 9, 2014 04:46
-
-
Save pipiscrew/21a740ac95538988a652 to your computer and use it in GitHub Desktop.
[php+mysql] read multiple recordset from procedure
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//ref : http://stackoverflow.com/questions/8710238/fetch-multiple-recordset-using-mysqli-object | |
//mysql | |
DELIMITER $$ | |
CREATE PROCEDURE `multiple`() | |
BEGIN | |
SELECT * FROM account; | |
SELECT * FROM admin; | |
END $$ | |
//php | |
//connection | |
$mysqli = new mysqli('hostname','username','password','db_name'); | |
// Check for errors | |
if(mysqli_connect_errno()){ | |
echo mysqli_connect_error(); | |
} | |
//prepare statement | |
$stmt = $mysqli->prepare("call multiple()"); | |
//run statement | |
$stmt->execute(); | |
//fetch all recorsets returned by procedure | |
$recordset_Counter = 0; | |
while ( $stmt->more_results() ) | |
{ | |
echo "Recordset($recordset_Counter) : <br/>"; | |
$res = $stmt->get_result(); | |
//fetch all records from current recordset | |
while( $row = $res->fetch_assoc() ) | |
{ print_r($row); echo "<br/>"; } | |
$stmt->next_result(); | |
$recordset_Counter++; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment