How to get MySQL procedure results _php Tutorial via PHP

Source: Internet
Author: User
There are always netizens asked me, how to call the MySQL stored procedure through PHP to get the returned result set? Indeed, MySQL's stored procedures greatly facilitate programming and improve efficiency. However, for those who are still using PHP 4 can be troublesome, because PHP 4 can only call the stored procedure, but can not directly get the return result set, but with PHP 5 mysqli function will do. First, recompile PHP 5, add support for mysqli, or download the mysqli extension directly, no longer in detail. Just give me an example:

1. Create a stored procedure that lists all the tables under the test library:

Mysql>delimiter//

Mysql>create PROCEDURE ' Yejr ' ()

->begin

->show TABLES;

->end; //

Query OK, 0 rows affected (0.12 sec)

Mysql>delimiter;

Mysql>call Yejr ();

+------------------+

| Tables_in_test |

+------------------+

| YEJR1 |

| YEJR2 |

+------------------+


2, write the test code with MYSQLI:

$mysqli = new Mysqli ("localhost", "root", "" "," Test ");

if (Mysqli_connect_errno ()) {

printf ("Connect failed:%sn", Mysqli_connect_error ());

Exit ();

}

$query = "Call Yejr ();";

if ($result = $mysqli->query ($query)) {

while ($row = $result->fetch_row ())

{

printf ("Find table:%s n", $row [0]);

}

}

$result->close ();

?>


The results are broadly as follows:

Find TABLE:YEJR1

Find TABLE:YEJR2

"Related articles"


http://www.bkjia.com/PHPjc/446764.html www.bkjia.com true http://www.bkjia.com/PHPjc/446764.html techarticle There are always netizens asked me, how to call the MySQL stored procedure through PHP to get the returned result set? Indeed, MySQL's stored procedures greatly facilitate programming and improve efficiency. However, for ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.