php调用存储过程返回结果集,解决can't return a result set in the given context错误的方法
2009-12-31 09:10
886 查看
需要php调用存储过程,返回一个结果集,发现很困难,找了半天,终于在老外的论坛上找到解决方案,这里本地化一下。
关键就是两点
1)define('CLIENT_MULTI_RESULTS', 131072);
2)$link = mysql_connect("127.0.0.1", "root", "",1,CLIENT_MULTI_RESULTS) or die("Could not connect: ".mysql_error());
下面就可以正常使用了,以下是例子程序。
<?php
define('CLIENT_MULTI_RESULTS', 131072);
$link = mysql_connect("127.0.0.1", "root", "",1,CLIENT_MULTI_RESULTS) or die("Could not connect: ".mysql_error());
mysql_select_db("vs") or die("Could not select database");
?>
<?php
$result = mysql_query("call get_news_from_class_id(2)") or die("Query failed:" .mysql_error());
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
$line = '<tr><td><a target = _blank href=/''.$row["url"].'/'>'.$row["title"].'('.$row["page_time"].')'.'</a></td></t
r>';
echo $line;
printf("/n");
}
mysql_free_result($result);
?>
<?php
mysql_close($link);
?>
关键就是两点
1)define('CLIENT_MULTI_RESULTS', 131072);
2)$link = mysql_connect("127.0.0.1", "root", "",1,CLIENT_MULTI_RESULTS) or die("Could not connect: ".mysql_error());
下面就可以正常使用了,以下是例子程序。
<?php
define('CLIENT_MULTI_RESULTS', 131072);
$link = mysql_connect("127.0.0.1", "root", "",1,CLIENT_MULTI_RESULTS) or die("Could not connect: ".mysql_error());
mysql_select_db("vs") or die("Could not select database");
?>
<?php
$result = mysql_query("call get_news_from_class_id(2)") or die("Query failed:" .mysql_error());
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
$line = '<tr><td><a target = _blank href=/''.$row["url"].'/'>'.$row["title"].'('.$row["page_time"].')'.'</a></td></t
r>';
echo $line;
printf("/n");
}
mysql_free_result($result);
?>
<?php
mysql_close($link);
?>
相关文章推荐
- php调用存储过程返回结果集,解决can't return a result set in the given context错误的方法
- PHP调用存储过程失败(没有执行到)--mysql_error()--can't return a result set in the given context
- php调用存储过程返回结果集,解决can't return a result set in the given context错误的方法
- php调用存储过程返回结果集,解决can't return a result set in the given context错误的方法
- php5.3 中显示Deprecated: Assigning the return value of new by reference is deprecated in 的解决方法
- php5.3 中显示Deprecated: Assigning the return value of new by reference is deprecated in 的解决方法
- EVP_DecryptFinal_ex调用返回失败,解密数据错误的解决方法
- "对COM 组件的调用返回了错误 HRESULT E_FAIL"的解决方法
- Ubuntu报“xxx is not in the sudoers file.This incident will be reported” 错误解决方法
- 错误:No resource found that matches the given name 'Theme.AppCompat.Light'解决方法
- MyBatis调用存储过程,含有返回结果集、return参数和output参数 .
- 【转载】PHP使用empty检查函数返回结果时报Fatal error: Can't use function return value in write context的问题
- 错误"Unable to find manifest signing certificate in the certificate store"的解决方法
- C# The given key was not present in the dictionary.错误原因及解决办法。
- Invalid character in the given encoding. Line XX, position XX.解决方法
- iPhone 自检工程错误解决方法:loaded the "MyView" nib but the view outlet was not set
- php出现[#2002 Cannot log in to the MySQL server]解决方法
- 使用jdbc调用oracle b294 存储过程(返回cursor)的错误及解决方法- -
- 调用Ajax返回500错误的解决方法
- "对COM 组件的调用返回了错误 HRESULT E_FAIL"的解决方法