This article describes how to solve the inconsistency between the returned values of stored procedure calls in PHP, and analyzes the causes and solutions of inconsistency between the returned values of stored procedure calls in the form of instances, for more information about how to solve the inconsistent returned values of PHP stored procedure calls, see the example in this article. We will share this with you for your reference. The details are as follows:
Today, when I talked to a student about the returned value of the stored procedure, I often got the unexpected value of null. because there was something during the day, I put an experiment here at night for the students who had the problem to check it out.
Stored Procedure:
delimiter//createprocedureusp_s2(outpar1int)beginselectinet_ntoa(ip),portfromproxy_listlimit5;selectcount(*)intopar1fromproxy_list;END//delimiter;
Session 1 execution:
mysql>callusp_s2(@a);+—————+——+|inet_ntoa(ip)|port|+—————+——+|1.34.21.86 |8088||1.34.59.50 |8088||1.34.69.15 |8088||1.34.73.110 |8088||1.34.76.218 |8088|+—————+——+5rowsinset(0.00sec)QueryOK,1rowaffected(0.01sec)mysql>select@a;+——+|@a |+——+|4430|+——+1rowinset(0.00sec)
Session 2 execution:
mysql>select@a;+——+|@a |+——+|NULL|+——+1rowinset(0.00sec)
The results of the two sessions are inconsistent. Basically, the two calls will get different values if they fall into different sessions.
For consistency, you can use the following call:
<?php$hostname="127.0.0.1";$username="wubx";$password="wubxwubx";$database="proxydb";$db=newmysqli($hostname,$username,$password,$database);if(mysqli_connect_errno()){ printf("Connect failed: %s\n",mysqli_connect_error()); exit();}$result=$db->multi_query("call usp_s2(@total); select @total;");if($result){ do{ if($r=$db->store_result()){ if($r->field_count==2){ while($row=$r->fetch_row()){ print"ip: $row[0], port: $row[1]\n"; } }else{ $row =$r->fetch_row(); print"total: $row[0]\n"; } } }while($db->next_result());}$db->close();?>
$ Phpt_proc_return.php
Ip: 1.34.21.86 and port: 8088
Ip: 1.34.59.50, port: 8088
Ip: 1.34.69.15 and port: 8088
Ip: 1.34.73.110 and port: 8088
Ip: 1.34.76.218 and port: 8088
Total: 4430
Good luck.