请教mysql存储过程执行成功,php却取不到值
begin
declare tmp varchar(100);
declare tmpjf int(10);
if empid>0 then
#select REPLACE(empfixed,'.',',' ) from kyydemploy where id=empid into @tmp;
select substring(REPLACE(empfixed,'.',',' ) ,2,char_length(empfixed) -2) into @tmp from kyydemploy where id=empid ;
end if;
set @sel='select sum(dejifen) into @tmpjf from kyydeinter where id in (';
set @selt=')';
set @conds=concat(@sel,@tmp,@selt);
prepare stmt from @conds;
execute stmt;
deallocate prepare stmt;
select @tmpjf into bb;
end
其中bb是返回字值 int类型。
用 cmd ,navicat 都能执行。但是在php下获取不到值。也用过简单的存储过程 select 888 into bb; 在php却能获取到。麻烦大虾看看是哪里不对?
回复讨论(解决方案)
你的存储过程会返回2个结果集(如果条件 empid>0 成立就是 3 个结果集)
但 mysql 函数组没有移动结果集指针的函数,所以读取不到 select @tmpjf into bb; 的结果(位于最后一个结果集中)
你需要使用 mysqli 函数组或 PDO 类来操作
这也就是 php 5.5 抛弃了 mysql 函数组的原因之一
你的存储过程会返回2个结果集(如果条件 empid>0 成立就是 3 个结果集)
但 mysql 函数组没有移动结果集指针的函数,所以读取不到 select @tmpjf into bb; 的结果(位于最后一个结果集中)
你需要使用 mysqli 函数组或 PDO 类来操作
这也就是 php 5.5 抛弃了 mysql 函数组的原因之一
明白了。3Q.也就是说 存储函数最好只返回单一的结果急麻
在不更换数据库操作扩展(换了,程序改动量也不小)你可以尝试在查询中执行 mysql_next_result 函数
25.2.3.45. mysql_next_result()int mysql_next_result(MYSQL *mysql) 描述如果存在多个查询结果,mysql_next_result()将读取下一个查询结果,并将状态返回给应用程序。如果前面的查询返回了结果集,必须为其调用mysql_free_result()。调用了mysql_next_result()后,连接状态就像你已为下一查询调用了mysql_real_query()或mysql_query()时的一样。这意味着你能调用mysql_store_result()、mysql_warning_count()、mysql_affected_rows()等等。如果mysql_next_result()返回错误,将不执行任何其他语句,也不会获取任何更多的结果,请参见25.2.9节,“多查询执行的C API处理”。返回值

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

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Laravel simplifies handling temporary session data using its intuitive flash methods. This is perfect for displaying brief messages, alerts, or notifications within your application. Data persists only for the subsequent request by default: $request-

The PHP Client URL (cURL) extension is a powerful tool for developers, enabling seamless interaction with remote servers and REST APIs. By leveraging libcurl, a well-respected multi-protocol file transfer library, PHP cURL facilitates efficient execution of various network protocols, including HTTP, HTTPS, and FTP. This extension offers granular control over HTTP requests, supports multiple concurrent operations, and provides built-in security features.

Laravel provides concise HTTP response simulation syntax, simplifying HTTP interaction testing. This approach significantly reduces code redundancy while making your test simulation more intuitive. The basic implementation provides a variety of response type shortcuts: use Illuminate\Support\Facades\Http; Http::fake([ 'google.com' => 'Hello World', 'github.com' => ['foo' => 'bar'], 'forge.laravel.com' =>

PHP logging is essential for monitoring and debugging web applications, as well as capturing critical events, errors, and runtime behavior. It provides valuable insights into system performance, helps identify issues, and supports faster troubleshoot

Do you want to provide real-time, instant solutions to your customers' most pressing problems? Live chat lets you have real-time conversations with customers and resolve their problems instantly. It allows you to provide faster service to your custom

Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo

The article discusses adding custom functionality to frameworks, focusing on understanding architecture, identifying extension points, and best practices for integration and debugging.

Alipay PHP...
