Why PHP calls a stored procedure to return multiple result sets, always one more result set

Source: Internet
Author: User
Tags php database
Like what
$db->query ("SET NAMES UTF8");
if ($db->real_query ("Call Sp_test ()")) {
do{
Echo ' BP ';
if ($result = $db->store_result ()) {
while ($row = $result->fetch_assoc ()) {
Array_push ($rows, $row);
}
$result->close ();
}
}while ($db->next_result ());
}
$db->close ();

You will find that assuming you return 1 result sets, you will hit 2 bp,2 result sets will echo out 3 BP, but if not write storage, directly write statements, it is normal, will not be more than one, ask the big God guidance Maze!


Reply to discussion (solution)

Isn't that normal? Otherwise you want if ($result = $db->store_result ()) {What do you do?

Isn't that normal? Otherwise you want if ($result = $db->store_result ()) {What do you do?

Hello, but the direct write statement in PHP will not be more than one, such as select 1;select 2;

He hit 2 BP, which is why, in the stored procedure also write the above 2 sentences will be out of 3

PHP database functions do not support shapes such as select 1;select 2; Such a query, and therefore cannot be used as a reference frame

   do{           if ($result = $db->store_result ()) {           }       }while ($db->next_result ());   
Such a code structure is required to read the stored procedure result set, if you think it is a bug, you can go to the PHP bug website to complain.
But you still have to do it before you fix it.

PHP database functions do not support shapes such as select 1;select 2; Such a query, and therefore cannot be used as a reference frame

   do{           if ($result = $db->store_result ()) {           }       }while ($db->next_result ());   
Such a code structure is required to read the stored procedure result set, if you think it is a bug, you can go to the PHP bug website to complain.
But you still have to do it before you fix it.

Thank you so much

Because your echo is written in front of the IF ($result = $db->store_result ()) {, and there is no result to see if ($result = $db->store_result ()) {The result of the judgment is not known, So there must be 2 results when, if to judge 3 times, that is, you say 3 times BP

In fact, simply put, your confusion lies in

$i = 1; $max = 2;while (true) {echo "A";//This will definitely output 3 AIF ($i > $max) {break    ;} $i + +;}

PHP database functions do not support shapes such as select 1;select 2; Such a query, and therefore cannot be used as a reference frame

   do{           if ($result = $db->store_result ()) {           }       }while ($db->next_result ());   
Such a code structure is required to read the stored procedure result set, if you think it is a bug, you can go to the PHP bug website to complain.
But you still have to do it before you fix it.

Hero, I am sorry, I also want to ask, $result = $db->store_result (), this sentence exactly what meaning, this is the assignment operation, how can return bool value?

$db->store_result () returns a query result resource
When it is gone, the return is empty (null)

$db->store_result () returns a query result resource
When it is gone, the return is empty (null)

That $result =null This return is false?

It's true that an assignment expression can return false,php.

Is I understand wrong, shipped to if inside judge is only $result value!!

  • Related Article

    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.