【发布时间】:2014-06-05 10:38:47
【问题描述】:
我正在努力在另一个存储过程中调用一个存储过程。就像现在存储过程永远不会将 SELECT 语句作为结果返回给 PHP 中的 mysqli 调用(但它在 MySQL 工作台中工作正常)。
DELIMITER $$
CREATE DEFINER=`root`@`localhost` PROCEDURE `new_bid`(IN bid_in decimal(6,2),
IN ticker_in varchar(5),
IN share_amount_in BIGINT)
BEGIN
DECLARE company_id_var INT;
DECLARE highest_bid BIT;
DECLARE generated_bid_id BIGINT;
SET company_id_var = (SELECT ID
FROM Companies
WHERE Ticker = ticker_in);
-- Put the bid into the Bids table.
INSERT INTO Bids(company_id,bid,share_amount)
VALUES (company_id_var,bid_in,share_amount_in);
SET generated_bid_id = LAST_INSERT_ID();
CALL check_available_shares(bid_in,share_amount_in,generated_bid_id,@shares_left);
-- Check if the bid is higher than the current highest bid.
-- If so update the CurrentState table to have the new value.
UPDATE CurrentState SET buyer = bid_in
WHERE ID = company_id_var
AND buyer < bid_in;
IF (ROW_COUNT() = 1)
THEN
SELECT 1 AS highest_bid, @shares_left AS shares_left, CS.buyer, CS.seller, CS.last_price, CO.name, CO.ticker
FROM CurrentState CS, Companies CO
WHERE CS.id = CO.id
AND CO.ticker = ticker_in;
ELSE
SELECT 0 AS highest_bid, @shares_left AS shares_left, CS.buyer, CS.seller, CS.last_price, CO.name, CO.ticker
FROM CurrentState CS, Companies CO
WHERE CS.id = CO.id
AND CO.ticker = ticker_in;
END IF;
END
如果我从这个存储过程中删除“CALL”函数,它将返回底部的 SELECT 语句之一,但如果我保留“CALL”函数,它不会返回任何内容。 我曾尝试使用 exec 并执行,但是当我尝试将过程保存在 MySQL 工作台中时,这只会给我语法错误。此问题与https://stackoverflow.com/questions/23193085/mysqli-does-not-return-any-results-but-stored-procedure-does 有关。 但似乎这个问题可能与mysqli如何处理存储过程的执行有关,因为当我在mySQL workbench中手动调用存储过程时它工作正常(?)
【问题讨论】:
标签: php mysqli mysql-workbench