PHP invokes the MySQL stored procedure

Source: Internet
Author: User
Tags php mysql

MySQL seems to start from 5.0 before the introduction of stored procedures, anyway before the application has never touched, but now because the main internal system, so many applications are used to the stored procedures, of course, the front sometimes need to call the MySQL stored procedures, php MySQL Lib seems to support is not very good, however, I searched some information, although not many, but still try to use, now introduce the method, so that the use of friends no longer have a headache.

The MySQL extension is also supported for stored procedures, but it only supports stored procedures that do not return results, and if the stored procedure has output, the call throws an error, and the specific error is forgotten. The invocation method is simple:

$rs = mysql_query ("Call func (' str ')", $conn);

If there is a return result, such as a return string, an error is shown, and the solution I have now found is to use the mysqli extension:

$rs = Mysqli_query ("Call func (' str ')", $conn);

So $rs as a common MySQL result to use, very convenient.

When you call a stored procedure, you may also encounter a problem, that is, you may call multiple stored procedures sequentially, which will also be the error, the solution is to call a stored procedure and processing completed, manually shut down the MySQL link, and then connect again, and then call another stored procedure to process, Number of times the number of stored procedures that need to be invoked is reconnected.

Related Article

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.