Home > Backend Development > PHP Tutorial > PHP calls MySQL stored procedure_PHP tutorial

PHP calls MySQL stored procedure_PHP tutorial

WBOY
Release: 2016-07-21 14:52:10
Original
737 people have browsed it

MySQL seems to have only introduced stored procedures since 5.0. Anyway, I have never touched them when I was doing applications before. But now because it is mainly used for internal systems, many applications use stored procedures. Of course, the front desk sometimes needs them. To call MySQL stored procedures, PHP's MySQL Lib doesn't seem to support it very well. However, I searched for some information. Although there is not much, I still tried to use it. Now I will introduce the method so that friends who use it will not have a headache.

MySQL extension also supports stored procedures, but only supports stored procedures that do not return results. If the stored procedure has output, this call will throw an error. The specific error is forgotten. The calling method is very simple:

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

If this returns a result, such as a string, an error will be reported. The solution I have found now is to use the MySQLi extension:

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

This way $rs can be used as an ordinary MySQL Result, which is very convenient.

When calling a stored procedure, you may also encounter a problem, that is, multiple stored procedures may be called sequentially, which will also report an error. The solution is to manually close MySQL after calling a stored procedure and completing the processing. Link, then connect again, then call another stored procedure and process it. Reconnect as many times as you need to call the stored procedure.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/371654.htmlTechArticleMySQL seems to have only introduced stored procedures since 5.0. Anyway, I have never touched it when I was doing applications, but now because It is mainly used for internal systems, so many applications use stored procedures. When...
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