PHP calls the MySQL stored procedure

Source: Internet
Author: User
MySQL seems to have introduced the stored procedure since MySQL 5.0, but it has never been touched before. However, because it is mainly used as an internal system, many applications use the stored procedure, of course, the front-end sometimes needs to call the MySQL stored procedure. PHP MySQLLib does not seem to support

MySQL seems to have introduced the stored procedure since MySQL 5.0, but it has never been touched before. However, because it is mainly used as an internal system, many applications use the stored procedure, of course, the front-end sometimes needs to call the MySQL stored procedure. the MySQL Lib in PHP does not seem to support very well, but I have searched some materials. although there are not many materials, I still tried to use them, now let's introduce the method so that you don't have to worry about it.

The lMySQL extension also supports stored procedures, but only supports stored procedures with no returned results. if the stored procedure has output, an error will be thrown during this call, and the specific error is forgotten. The call method is simple:

$ Rs = mysql_query ("call func ('str')", $ conn );

If a returned result is returned, for example, a string, an error is returned. the solution I have found is to use the MySQLi extension:

$ Rs = mysqli_query ("call func ('str')", $ conn );

In this way, $ rs is used as a normal MySQL Result, which is very convenient.

When calling a stored procedure, you may encounter another problem, that is, you may call multiple stored procedures in sequence, which also reports an error, the solution is to manually close the MySQL link after a stored procedure is called and processed, connect again, and call another stored procedure for further processing. how many stored procedures need to be called, the number of reconnections.

Because I am not very familiar with MySQL extensions, the above is a summary of experience.

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.