How to obtain MySQLprocedure result through PHP _ MySQL

Source: Internet
Author: User
How can I obtain MySQLprocedure results through PHP? some netizens asked me, how can I call the MySQL stored procedure through php to get the returned result set at the same time? Indeed, the MySQL stored procedure greatly facilitates programming and improves efficiency. However, it is troublesome for those still using php 4, because php 4 can only call the stored procedure, but cannot directly obtain the returned result set. However, you can use the mysqli function of php 5. First, recompile php 5 to add support for mysqli, or directly download the extension module of mysqli. For example:

1. create a stored procedure to list all tables in the test database:

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. use mysqli to compile the test code:

$ Mysqli = new mysqli ("localhost", "root", "", "test"); if (mysqli_connect_errno () {printf ("Connect failed: % s/n ", 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 as follows:

Find table: yejr1

Find table: yejr2

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.