Two days ago, I developed an inventory management system with my colleagues. I was responsible for writing the page program, and my colleague was responsible for writing the stored procedure. When writing the program, everything went smoothly until the development was completed. When I used PHP to call his stored procedure, a problem occurred.
You need to pay attention to the following points when developing in the future:
1. When connecting to the MYSQL database, pay attention to the last two parameters
define('CLIENT_MULTI_RESULTS', 131072); //Define constants
$conn=mysql_connect("localhost","root","123456",1,CLIENT_MULTI_RESULTS);
$db=mysql_select_db("db01",$conn);
2. Call the stored procedure method
It’s very simple. There are two methods
(1)No return value
mysql_query("call nj_keep_accounts_sp($id)",$conn); // Stored procedure name: nj_keep_accounts_sp Parameter: $id
(2) There is a return value
$id=$_GET["id"];
$r=mysql_query("call nj_keep_accounts_sp($id)",$conn);
while($rs=@mysql_fetch_array($r)){
echo($rs["t_id"]);
}
3. If no error is reported during debugging, the execution is often unstable. It works well for a while and not for a while. Please note
This happened to me during testing, and I found that there were no errors in the code itself, and there were no errors when the stored procedure was executed in MYSQL. Where did the problem occur?
After two days of testing, it was finally discovered that when writing the stored procedure, test return values were added at the beginning, middle, and end of the execution during the debugging process. The problem occurs here.
After I commented all the useless return values (such as: select @a) and similar code, I found that all the previous problems were solved and the program became easier to use.
Excerpted from newsera