[英]Setting MySQL procedure results to PHP variables
I am trying to set the two outputs from this MySQL stored procedure as PHP variables: 我试图将此MySQL存储过程的两个输出设置为PHP变量:
$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
. 最后两行抛出错误
Trying to get property of non-object
。 Does anybody know the proper way to do this? 有人知道这样做的正确方法吗?
mysql_fetch_object instead of mysql_fetch_assoc should fix your query up. mysql_fetch_object代替mysql_fetch_assoc应该可以解决您的查询问题。
Secondly though you should really look at either using mysqli_ or pdo statements. 其次,尽管您应该真正使用mysqli_或pdo语句。
Links here: 链接在这里:
Here's how I got it to work with mysql_query
: 这是我如何使其与
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. 在该过程之后,我调用了
SELECT
语句,然后在while循环中,正确设置了$ eset变量。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.