从存储过程中获取记录?

时间:2012-12-01 11:44:03

标签: php mysql stored-procedures

我疯了这样的存储过程:

DELIMITER //
DROP PROCEDURE IF EXISTS `get_games_menu` //

CREATE PROCEDURE `get_games_menu`
(
IN currplayer INT,
OUT gameid INT,
OUT lastdraw INT,
OUT playertiles TEXT,
OUT oppnation INT,
OUT oppname VARCHAR(100),
OUT fdraw INT,
OUT playerpoints INT,
OUT infopop INT,
OUT oppTiles TEXT,
OUT tabletiles TEXT,
OUT playerturn INT,
OUT newtabletiles TEXT,
OUT profileimg VARCHAR(255)
)
BEGIN
SELECT 
    gp.fk_game_id
  , gp.player_tiles
  , gp.infoPop
  , gp.first_draw
  , gp.player_points
  , g.table_tiles
  , g.new_tiles
  , gp2.last_draw_type
  , gp2.player_turn
  , gp2.player_tiles
  , u.country
  , u.username
  , u.profileimg
INTO 
    gameid
  , playertiles
  , infopop
  , fdraw
  , playerpoints
  , tabletiles
  , newtabletiles
  , lastdraw
  , playerturn
  , oppTiles
  , oppnation
  , oppname
  , profileimg
FROM nf_gameplayer gp
INNER JOIN nf_games g 
ON gp.fk_game_id = g.game_id
INNER JOIN nf_gameplayer gp2
ON  gp.fk_game_id = gp2.fk_game_id
AND gp.fk_player_id != gp2.fk_player_id
INNER JOIN nf_users u
ON gp2.fk_player_id = u.id
WHERE gp.fk_player_id = currplayer 
AND   g.invite=0 
AND   g.deleteby != currplayer 
ORDER BY g.lastdraw;
END //
DELIMITER ;

然后我试着这样称呼它:

$mysqli = new mysqli('localhost', 'root', '', 'mytest');

$rs = $mysqli->query( 'CALL get_games_menu(1, @gameid,@playertiles,@infopop,@fdraw,@playerpoints,@tabletiles,@newtabletiles,@lastdraw,@playerturn,@opptiles,@oppnation,@oppname,@profileimg)' );
$rs = $mysqli->query( 'SELECT @gameid,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL');
while($row = $rs->fetch_object())
{
    echo $row['gameid']-'<br>';
}

但我没有得到任何记录。在做一个普通的mysql时,我得到9条记录......

我做错了什么。 (存储过程新增功能。)

提前致谢; - )

1 个答案:

答案 0 :(得分:0)

CALL get_games_menu(1,@ gameid) 传递get_games_menu中所有变量的值。 其他设定 CALL get_games_menu(1,@ gameidm,NULL,NULL等。)