Reputation: 825
I am trying to set the two outputs from this MySQL stored procedure as PHP variables:
$result = mysql_query("CALL mst2('$q', @eset, @leng)");
if (!$result) {
die('Invalid query: ' . mysql_error());
}
while($row = @mysql_fetch_assoc($result))
{
debug($row);
}
$eset = $row->{'@eset'};
$length= $row->{'@leng'};
The last two line are throwing an error Trying to get property of non-object
. Does anybody know the proper way to do this?
Upvotes: 0
Views: 403
Reputation: 825
Here's how I got it to work with mysql_query
:
$result = mysql_query("CALL mst2('$q', @eset, @leng)");
$result = mysql_query("SELECT @eset, @leng");
if (!$result) {
die('Invalid query: ' . mysql_error());
}
while($row = @mysql_fetch_object($result))
{
$eset = $row->{'@eset'};
}
right after the procedure I called a SELECT
statement, then in the while loop, the $eset variable gets set properly.
Upvotes: 1
Reputation: 4423
mysql_fetch_object instead of mysql_fetch_assoc should fix your query up.
Secondly though you should really look at either using mysqli_ or pdo statements.
Links here:
Upvotes: 2