如何创建存储过程phpMyAdmin

时间:2014-05-02 15:37:33

标签: php mysql phpmyadmin

我尝试创建这样的商店程序:

CREATE PROCEDURE UserReserveRoom (@user varchar(8))
begin
SELECT FirstName,LastName,Rtype, checkin, checkout, RoomPrice
FROM room INNER JOIN register ON room.username = register.username
WHERE username like @user
end 

当我像这样执行phpMyAdmin警告时:

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your
MySQL server version for the right syntax to use near '@user varchar(8)) begin 
SELECT FirstName,LastName,Rtype, checkin, checkout, Ro' at line 1

我试着说:

  

定界符     DROP程序如果存在UserReserveRoom;

但它不起作用。我怎么做才能解决它? 我感谢有此类事务经验的用户提供的任何反馈。 谢谢你。

3 个答案:

答案 0 :(得分:0)

你这样称呼它

CALL UserReserveRoom('whatevervalue s_user is here');

或使用php:

$mysqli->query("CALL UserReserveRoom('whatevervalue s_user is here')");

答案 1 :(得分:0)

这是较新版本的phpMyAdmin

中的正确语法
DROP PROCEDURE IF EXISTS UserReserveRoom; 

CREATE PROCEDURE UserReserveRoom (IN user varchar(8))

SELECT FirstName,LastName,Rtype, checkin, checkout, RoomPrice
FROM room INNER JOIN register ON room.username = register.username
WHERE username like user;

然后,您使用以下语法通过phpMyAdmin调用该过程:

SET @user='xyz';
CALL UserReserveRoom(@user);

答案 2 :(得分:-1)

试试这个:

DELIMITER //

CREATE PROCEDURE UserReserveRoom(IN s_user VARCHAR(8))
BEGIN
    SELECT FirstName, LastName, Rtype, checkin, checkout, RoomPrice
    FROM room INNER JOIN register ON room.username = register.username
    WHERE room.username = s_user;
END //

DELIMITER ;