PHP calls stored procedure to return result set

巴扎黑
Release: 2016-11-12 13:49:40
Original
2124 people have browsed it

php calls a stored procedure to return a result set, and the method to solve the error of can't return a result set in the given context

requires php to call a stored procedure and return a result set. I found it very difficult. After searching for a long time, I finally found it on the foreigner's forum Found the solution on the website, localize it here.

The key is mysql_connect, add 1,131072 to the fourth parameter

$link = mysql_connect("127.0.0.1", "root", "",1,131072) or die("Could not connect: ".mysql_error ());

The following can be used normally. The following is an example program.

<?php    define(&#39;CLIENT_MULTI_RESULTS&#39;, 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");?>
Copy after login
<?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 = &#39;<tr><td><a target = _blank href=\&#39;&#39;.$row["url"].&#39;\&#39;>&#39;.$row["title"].&#39;(&#39;.$row["page_time"].&#39;)&#39;.&#39;</a></td></tr>&#39;;                echo $line;                printf("\n");
        }        mysql_free_result($result);        ?>
Copy after login
<?php
    mysql_close($link);
?>
Copy after login


source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!