问题描述:

I'm try to create store procedure like this:

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

When I executed phpMyAdmin alert like this:

#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

I try to put:

delimiter

DROP PROCEDURE IF EXISTS UserReserveRoom;

But it doesn't work. How I can do to fix it??

I appreciate any feedback from users who have experience in such matters.

Thanks you.

网友答案:

you call it like so also

CALL UserReserveRoom('whatevervalue s_user is here');

or with php:

$mysqli->query("CALL UserReserveRoom('whatevervalue s_user is here')");
网友答案:

This is the correct syntax in newer versions of 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;

And then, you call the procedure via phpMyAdmin using the following syntax:

SET @user='xyz';
CALL UserReserveRoom(@user);
网友答案:

Try this:

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 ;
相关阅读:
Top