note 96048 added to mysqli.store-result
| From: | mitchind at osu1 dot php dot net | Date: | Fri, 05 Feb 2010 04:28:26 +0000 |
| Subject: | note 96048 added to mysqli.store-result | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-165681@lists.php.net to get a copy of this message | ||
After reading through original notes and example above as well as wading through the documentation,
I finally got a loop to work with two stored procedures.
Using the results of the first one as a parameter for the second one. Easier to do this way than a
huge modified sequence of Inner Join queries.
Hope this helps others...
<?php
// Connect to server and database
$mysqli = new mysqli("$dbServer", "$dbUser", "$dbPass",
"$dbName");
// Open First Stored Procedure using MYSQLI_STORE_RESULT to retain for looping
$resultPicks = $mysqli->query("CALL $proc ($searchDate, $maxRSI, $incRSI, $minMACD, $minVol,
$minTrades, $minClose, $maxClose)", MYSQLI_STORE_RESULT);
// process one row at a time from first SP
while($picksRow = $resultPicks->fetch_array(MYSQLI_ASSOC)) {
// Get Parameter for next SP
$symbol = $picksRow['Symbol'];
// Free stored results
clearStoredResults($mysqli);
// Execute second SP using value from first as a parameter (MYSQLI_USE_RESULT and free result right
away)
$resultData = $mysqli->query("CALL prcGetLastMACDDatesBelowZero('$symbol',
$searchDate)", MYSQLI_USE_RESULT);
$dataRow = $resultData->fetch_array(MYSQLI_ASSOC);
// Dump result from both related queries
echo "<p>$symbol ... Num Dates: " . $dataRow['NumDates'];
// Free results from second SP
$resultData->free();
}
// Free results from first SP
$resultPicks->free();
// close connections
$mysqli->close();
#------------------------------------------
function clearStoredResults($mysqli_link){
#------------------------------------------
while($mysqli_link->next_result()){
if($l_result = $mysqli_link->store_result()){
$l_result->free();
}
}
}
?>
----
Server IP: 192.41.40.227
Probable Submitter: 199.126.252.125
----
Manual Page -- http://www.php.net/manual/en/mysqli.store-result.php
Edit -- https://master.php.net/note/edit/96048
Del: integrated -- https://master.php.net/note/delete/96048/integrated
Del: useless -- https://master.php.net/note/delete/96048/useless
Del: bad code -- https://master.php.net/note/delete/96048/bad+code
Del: spam -- https://master.php.net/note/delete/96048/spam
Del: non-english -- https://master.php.net/note/delete/96048/non-english
Del: in docs -- https://master.php.net/note/delete/96048/in+docs
Del: other reasons-- https://master.php.net/note/delete/96048
Reject -- https://master.php.net/note/reject/96048
Search -- https://master.php.net/manage/user-notes.php