Home  >  Article  >  php教程  >  php调用存储过程返回结果集,解决cant return a result set in the given conte

php调用存储过程返回结果集,解决cant return a result set in the given conte

WBOY
WBOYOriginal
2016-06-13 10:32:22888browse

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

关键就是两点

1)define(CLIENT_MULTI_RESULTS, 131072);

2)$link = MySQL(和PHP搭配之最佳组合)_connect("127.0.0.1", "root", "",1,CLIENT_MULTI_RESULTS) or die("Could not connect: ".MySQL(和PHP搭配之最佳组合)_error());


下面就可以正常使用了,以下是例子程序。

 

(做为现在的主流开发语言)
    define(CLIENT_MULTI_RESULTS, 131072);

    $link = MySQL(和PHP搭配之最佳组合)_connect("127.0.0.1", "root", "",1,CLIENT_MULTI_RESULTS) or die("Could not connect: ".MySQL(和PHP搭配之最佳组合)_error());
    MySQL(和PHP搭配之最佳组合)_select_db("vs") or die("Could not select database");
?>

        (做为现在的主流开发语言)
        $result = MySQL(和PHP搭配之最佳组合)_query("call get_news_from_class_id(2)") or die("Query failed:" .MySQL(和PHP搭配之最佳组合)_error());
        while($row = MySQL(和PHP搭配之最佳组合)_fetch_array($result, MySQL(和PHP搭配之最佳组合)_ASSOC))
        {
                $line =

.$row["title"].(.$row["page_time"].).
r>;
                echo $line;
                printf(" ");

        }
        MySQL(和PHP搭配之最佳组合)_free_result($result);
        ?>

 

(做为现在的主流开发语言)
    MySQL(和PHP搭配之最佳组合)_close($link);
?>

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn