dongliehuan3925 2015-04-28 15:01
浏览 43

成功时从MySql中的存储过程返回一些内容

i'm making a school project, i have to build a bank and do transfers etc. so i've made two stored procedures, withdraw and deposit, both takes the account number and an amount as parameters.

CREATE DEFINER=`bank`@`localhost` PROCEDURE `withdraw`(
    IN p_account INT(11),
    IN p_amount DOUBLE
)
BEGIN

DECLARE p_balance double;
SELECT balance
INTO p_balance FROM
Accounts
WHERE
account_id = p_account;

IF p_balance >= p_amount THEN
UPDATE Accounts
SET balance = p_balance - p_amount
WHERE account_id = p_account;
//tell my php somehow
ELSE
//tell my php somehow
END IF;

END

i've been searching google dry, and i've tried:

to make a function and return a value from the function (some tutorial.. didnt work ofc xD)

to declare an output value (OUT p_result INT) and set the int, no luck

i've tried, to get that output value to work and im clueless.

what i want is in my php script

$sql = "CALL withdraw(1,500);"
$result = conn->query($sql);
if($result=true){
    conn->query("CALL deposit(2,500)");
} else {
    //inform user
} 

EDIT!: i now SELECT something in my procedures, in deposit() the return is an email address.

In withdraw() the return is the account that has been withdrawed. Both works fine 1 by 1. but when i do withdraw() first, and then deposit() if withdraw succeeded, then it my var_dump($result) = bool(false)

  • 写回答

1条回答 默认 最新

  • dongtu4559 2015-04-28 21:21
    关注

    Stored PROCEDURES can return a resultset. The last thing you SELECT in a stored procedure is available as a resultset to the calling environment.. Stored FUNCTIONS can return only a single result primitive.

    评论

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看