PHP Call stored procedure return value inconsistency problem resolution analysis, stored procedure inconsistency _php tutorial

Source: Internet
Author: User

Workaround analysis for PHP call stored procedure return value inconsistency problem, stored procedure inconsistent


This article describes a workaround for PHP calling stored procedure return value inconsistencies. Share to everyone for your reference, as follows:

I met a classmate today. Stored procedure return values often get an unexpected value of NULL, because during the day there is something to do in the evening to do an experiment here for the students with the corresponding problem to check.

Stored procedures:

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 were inconsistent. It is essential to be sure that two calls fall into different sessions and get different values.
In order to be consistent you can call as follows:

<?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,port:8088
ip:1.34.59.50,port:8088
ip:1.34.69.15,port:8088
ip:1.34.73.110,port:8088
ip:1.34.76.218,port:8088
total:4430

Good luck.

For more information about PHP related content readers can view the topic: "MySQL stored process skills Daquan", "PHP Data structure and algorithm tutorial", "PHP operation and operator Usage Summary", "PHP Network Programming Skills Summary", "PHP Basic Grammar Introductory Tutorial", " PHP Operations Office Documentation Tips Summary (including word,excel,access,ppt), PHP date and Time usage summary, PHP Object-oriented Programming primer tutorial, PHP string Usage Summary, php+ MySQL database operation Getting Started tutorial and PHP Common database operation Skills Summary

I hope this article is helpful to you in PHP programming.

http://www.bkjia.com/PHPjc/1123829.html www.bkjia.com true http://www.bkjia.com/PHPjc/1123829.html techarticle php Call stored procedure return value inconsistency problem resolution analysis, stored procedure inconsistency This article describes a workaround for PHP calling stored procedure return value inconsistency. Share to ...

  • 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.