您的位置:首页 > 编程语言 > PHP开发

php调用mysql存储过程返回结果集

2010-10-07 05:15 756 查看
关键就是两点
1 define(‘CLIENT_MULTI_RESULTS‘, 131072);
2
3 $link = mysql_connect(“127.0.0.1“, “root“, “”,1,CLIENT_MULTI_RESULTS) or die(“Could not connect: “.mysql_error());

下面就可以正常使用了,以下是例子程序。
1 2 define(‘CLIENT_MULTI_RESULTS‘, 131072);
3
4 $link = mysql_connect(“127.0.0.1“, “root“, “”,1,CLIENT_MULTI_RESULTS) or die(“Could not connect: “.mysql_error());
5 mysql_select_db(“vs“) or die(“Could not select database“);
6 ?>
7
8 9 $result = mysql_query(“call get_news_from_class_id(2)“) or die(“Query failed:“ .mysql_error());
10 while($row = mysql_fetch_array($result, MYSQL_ASSOC))
11 {
12 $line = ‘‘.$row["title"].‘(‘.$row["page_time"].‘)‘.‘‘;
14 echo $line;
15 printf(“/n“);
16
17 }
18 mysql_free_result($result);
19 ?>
20
21 22 mysql_close($link);
23 ?>
php调用存储过程返回结果集,解决can’t return a result set in the given context错误的方法

需要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());
下面就可以正常使用了,以下是例子程序。

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”);
?>

$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 = ‘’.$row["title"].’(‘.$row["page_time"].’)’.’’;
echo $line;
printf(“/n”);

}
mysql_free_result($result);
?>

mysql_close($link);
?>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: