MySQL has 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 to call them. MySQL stored procedures and PHP's MySQL Lib don'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.
lMySQL 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); Copy after login |
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); Copy after login |
This way $rs is 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 call a stored procedure and complete the processing. Manually close the MySQL connection, then connect again, and then call another stored procedure to process. Reconnect as many times as you need to call the stored procedure.