PHP调用存储过程返回值不一致问题的解决方法分析,存储过程不一致
本文实例讲述了PHP调用存储过程返回值不一致问题的解决方法。分享给大家供大家参考,具体如下:
今天遇一个同学聊存储过程返回值经常得到意外的值为null, 因为白天有事,晚上给做一个实验放在这里供有相应问题的同学查看一下。
存储过程:
delimiter// createprocedureusp_s2(outpar1int) begin selectinet_ntoa(ip),portfromproxy_listlimit5; selectcount(*)intopar1fromproxy_list; END// delimiter;
session 1执行:
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执行:
mysql>select@a; +——+ |@a | +——+ |NULL| +——+ 1rowinset(0.00sec)
可见两个session得到的结果不一致。 基本可以肯定两次调用落入不同的会话中会得到不同的值。
为了一致可以如用如下调用:
<?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.
更多关于PHP相关内容感兴趣的读者可查看本站专题:《MySQL存储过程技巧大全》、《PHP数据结构与算法教程》、《PHP运算与运算符用法总结》、《PHP网络编程技巧总结》、《PHP基本语法入门教程》、《php操作office文档技巧总结(包括word,excel,access,ppt)》、《php日期与时间用法总结》、《php面向对象程序设计入门教程》、《php字符串(string)用法总结》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》
希望本文所述对大家PHP程序设计有所帮助。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Atom editor mac version download
The most popular open source editor

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

Dreamweaver CS6
Visual web development tools

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),