Forum Moderators: coopster

Message Too Old, No Replies

Weird result set with stored procedure call

         

Tommybs

12:59 pm on May 29, 2010 (gmt 0)

10+ Year Member



Hi,

Not sure if this is related to PHP or mysql so please move if you think it is the latter.

I've been using stored procedure within php for a while now and am fairly used to the syntax. However I've got a interesting problem at the moment that I'm not sure how to rectify.

I've got a stored procedure that is return a result set that I am then passing to mysql_fetch_array();
i.e. in the format (select id,name FROM table ORDER by name);
If I go to the page in question that should display this result set, I receive the following error

mysql_fetch_array(): supplied argument is not a valid MySQL result resource

Then if I refresh the page and refresh it again whilst it is refreshing, it shows the correct output. A single refresh on its own shows the error. This has me really stumped and I'm not quite sure how to go about debugging the problem. I've tried clearing my cache, using different browsers and ctrl-f5 instead of just f5.

Just as a quick test I've even replaced the sproc call to an inline mysql_query statement and am getting the same issue!

Does anyone have any clues what's going on here? I know there are some issue with mysql sproc calls, but when doing it as inline sql I don't know why I'm getting an issue? There is no such problem in the command line which is what leads me to believe it's a php bug.

Thanks

Tommybs

1:29 pm on May 29, 2010 (gmt 0)

10+ Year Member



Ok after some more digging, it appears the issue is down to the resource identifier I'm passing in. I've checked the permissions and they are set correctly. I think the issue is down to having more than 1 mysql_connect statement selecting the same db. I know to use stored procedures properly I have to use the extra parameters
e.g. $d = mysql_connect("localhost", "user", "pass", false, 65536);
mysql_select_db("my_db", $d);
$w = mysql_connect("localhost", "user2", "pass2", false, 65536);
mysql_select_db("my_db", $w);

As $w is initialised second it seems to work if I don't pass in $d as the resource parameter. Can anyone recommend how I should structure this? I'd like to use the first connection for SELECT statements only. I'm then only allow the $w connection to do inserts,updates etc. I'm just trying to tidy up the SQL side of my site security but this is frustrating me.

Thanks