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

巴扎黑
巴扎黑 原创
2016-11-12 13:49:40 1652浏览

php调用存储过程返回结果集,解决can't return a result set in the given context错误的方法

需要php调用存储过程,返回一个结果集,发现很困难,找了半天,终于在老外的论坛上找到解决方案,这里本地化一下。

关键就是mysql_connect,第四个参数加上1,131072

$link = mysql_connect("127.0.0.1", "root", "",1,131072) 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></tr>';                echo $line;                printf("\n");
        }        mysql_free_result($result);        ?>
<?php
    mysql_close($link);
?>


声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。