/    Sign up×
Community /Pin to ProfileBookmark

Mysqli and multiple Stored Procedures

Ok I am having some struggles with getting multiple stored procedures to run together. I know you are supposed to free the results of each SP and check for additional resultset(s) and free those as well before running another query. I believe I am doing that and I am still not having any luck with it…function is below.

[code=php]
function scoreQuestion($tID, $qID)
{

$score = 0;

$sql = “CALL sProcedure()”;

if ($mysqli->query($sql))
{
do {
/* store first result set */
if ($result = $mysqli->use_result())
{
$x = 0;
while ($row = $result->fetch_row())
{
$aIDArr[$x] = $row[3];
$x++;
}
var_dump($result);
$result->free();
}
} while ($mysqli->next_result());
}

for($i = 0; $i < count($aIDArr); $i++)
{

$sql = “CALL secondProcedure()”;

$mysqli->query($sql);

$result = $mysqli->use_result(); //var_dump($result) returns bool(false)…even though I believe I have cleared the results already.

while($row = $result->fetch_row()) //Error occurs here
{
$score = $score + $row[0];
}

$result->close();
}

return (int)$score;
}
[/code]

Any help would be greatly appreciated!

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@dhuiauthorMay 27.2010 — Nvm. Figured it out!

Wasn;'t closing correctly for the stored procedures inside the for loop!
×

Success!

Help @dhui spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...