Hi,

I've just discovered mysql stored procedures and have been using PHP4 a few years now, but not as my day job. I can get a mysql stored procedure to execute and work in the PHP script, but I'm having problems executing multiple stored procedures. Each of them returns one recordset.

My connection string looks like this: mysql_connect(hostname,dbname,password,TRUE, 131072); A sample of my code that produces the error looks like this:

include('connection.php');

$sql = "CALL PlayerListPosition (2, 3, 4);";

$result = mysql_query($sql);

while ($rowresult = mysql_fetch_row($result))
{
	echo "$rowresult[0] <BR />";
}

$sql = "CALL PlayerListPosition (2, 1, 1);";

$result = mysql_query($sql);

while ($rowresult = mysql_fetch_row($result))
{
	echo "$rowresult[0] <BR />";
}

Now the first recordset works just fine, but when its time to run the second recordset I get a mysql_fetch_row error as below. Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource If I executed the second procedure on its own that works too.

Do I need to close the recordset before using the next one? How would I do this? I've tried running multiple in line sql SELECT statements and I dont get a problem - its only when I use multiple stored procedures in a page - that this error occurs.

I really would like to start using stored procedures now that I've discovered them so any help in getting around this problem would be great! Thanks.

Recommended Answers

All 3 Replies

Can anyone help? Surely someone must know how to run 2 stored procedures on a single PHP page?

same problem here :( .....

can anyone help us......

You need to use mysql_free_result($result) before you can use it again, or use a different variable name the second time.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.