0

Ok, I am rewriting my question to be more clear. See the following code:

//direct call to the proc. this works
$query = sprintf("CALL GetScores(%d);",$GameID );

print("<br/>call # 1<br/>");
$result = mysql_query($query, $_DB_link);
print_r(mysql_fetch_assoc($result ));


print("<br/>call # 2<br/>");
$result = mysql_query($query, $_DB_link);
print_r(mysql_fetch_assoc($result ));

Notice I am using the exact same query string in both calls to mysql_query. The first one returns good results. But the second one fails. Does PHP not allow two calls to thew same proc? Or does mysql not allow 2 calls to the same proc? it seems unlikely.. does anyone know what might be happening here? Why is mysql_query failing the second time?

the output of the above code is:

call # 1

Array ( [name] => Dratikus [score] => 123 )

call # 2

Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in /home/geekytec/public_html/test3.php on line 60

James
  • 535
  • 1
  • 5
  • 23
  • See [this answer](http://stackoverflow.com/a/11674313/250259) for how to troubleshoot this. – John Conde Dec 19 '13 at 01:42
  • so it seems like the server doesn't allow two calls to any stored procedures... is that normal? – James Dec 19 '13 at 01:51
  • Ok, I rewrote my question with a better code example. Hopefully this will prevent any more confusion. – James Dec 19 '13 at 02:00

2 Answers2

3

Every time you fetch the results, you change the result pointer. This is normal for all functions that work with internal result pointers. How do you know when a function is using an internal pointer? The documentation will tell you. Confused about what the documentation says? Search for those terms on the internet.

mysql_fetch_assoc:

Returns an associative array that corresponds to the fetched row and moves the internal data pointer ahead.

http://www.php.net/mysql_fetch_assoc

This might help: How to go through mysql result twice?

Edit:

I missed the line where you executed the query again. Throw a print_r($_DB_link) in there before each call. That error means that your resource is now false instead of the connection handle. You may be losing your connection for some reason.

Community
  • 1
  • 1
0

The main reason you get that error is that your query failed (as in bad query syntax). You either need to see if $result is false and then echo out mysql_error to see what went wrong (and I would take note of the big red block about the mysql_ functions being depreciated if I were you).

Machavity
  • 29,816
  • 26
  • 86
  • 96
  • Yes, I am asking why is it failing - notice how it is the exact same code getting executed twice? Why would the first one succeed and the second one fail? That can't be normal.. – James Dec 19 '13 at 01:53
  • Try changing the second `$result` to a different variable (bad practice to reuse variables anyways) and see if it makes a difference. – Machavity Dec 19 '13 at 03:01