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());

下面就可以正常使用了,以下是例子程序。
 
<?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);
?>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章