1

我试图制作这样的存储过程:

DELIMITER $$
DROP PROCEDURE IF EXISTS get_userStatUser $$
CREATE PROCEDURE get_UserStatUser
(
IN userId INT,
OUT Played INT,
OUT Win INT,
OUT Points INT
)
BEGIN
SELECT played, win, points
INTO Played, Win, Points
FROM nf_users
WHERE id = userId;
END $$
DELIMITER ;

然后我尝试像这样从中获取数据:

$sql = mysqli_query($connect,"CALL get_userStatUser()") or die("Query fail: " . mysqli_error());
$row = mysqli_fetch_array($sql);

$played = $row['Played'];
$win = $row['Win'];
$points = $row['Points'];

但有些不对劲。我是存储过程的新手,看不到哪里出错了?我得到“查询失败:”,但没有任何错误?

任何帮助都非常感谢,并在此先感谢:-)

4

1 回答 1

1

存储过程需要 4 个参数

IN userId INT,
OUT Played INT,
OUT Win INT,
OUT Points INT

鉴于您的 PHP 调用存储过程的方式,您需要重新定义以下内容:

DELIMITER $$
DROP PROCEDURE IF EXISTS get_userStatUser $$
CREATE PROCEDURE get_UserStatUser
(
IN userId INT
)
BEGIN
SELECT played, win, points
FROM nf_users
WHERE id = userId;
END $$
DELIMITER ;

你的 PHP

$given_userid = 372987;
$sql = mysqli_query($connect,"CALL get_userStatUser($given_userid)") or die("Query fail: " . mysqli_error());
$row = mysqli_fetch_array($sql);

$played = $row['played'];
$win = $row['win'];
$points = $row['points'];

试试看 !!!

于 2013-01-03T22:14:21.373 回答