我必须在mysql中使用存储过程插入数据。这是我对该SP的SP和函数调用。但是我无法使用它们插入值。你可以验证并告诉我该怎么做? SP是:
delimiter ; ;
DROP PROCEDURE IF EXISTS sp_insertUserDetails ; ;
CREATE PROCEDURE sp_insertUserDetails( )
BEGIN
INSERT INTO tbl_userDetails
( strEmail,bitAllowClicktoFBProfile,bitIsAbbreviateLastName, strAboutMe )
VALUES ($strEmail, $bitAllow, $bitAbbreviate, $strAbout);
END
从php文件调用此SP:
$query = mysql_query("CALL sp_insertUserDetails($strEmail, $bitAllow, $bitAbbreviate, $strAbout)");
答案 0 :(得分:1)
你没有为你的SP定义任何参数 - 你是否尝试直接从SQL调用它,例如:
mysql> call sp_insertUserDetails("foo", "bar", "dave", "str");
ERROR 1318 (42000): Incorrect number of arguments for PROCEDURE test.sp_insertUserDetails; expected 0, got 4
你需要这样的东西
DROP PROCEDURE IF EXISTS sp_name;
delimiter ;;
CREATE PROCEDURE sp_name(fname varchar (20), lname varchar(20))
BEGIN
SELECT concat('Hello ', fname, ',', lname);
END
;;
delimiter ;
答案 1 :(得分:0)
就这样做
这里我假设所有值都在varchar
DELIMITER //
DROP PROCEDURE IF EXISTS sp_insertUserDetails;
CREATE PROCEDURE sp_insertUserDetails(
IN strEmail varchar(255),
IN bitAllow varchar(255),
IN bitAbbreviate varchar(255),
IN strAbout varchar(255)
)
BEGIN
INSERT INTO tbl_userDetails
( strEmail,bitAllowClicktoFBProfile,bitIsAbbreviateLastName, strAboutMe )
VALUES (strEmail, bitAllow, bitAbbreviate, strAbout);
END //
DELIMITER ;
并像这样打电话
mysql_query( CALL sp_insertUserDetails($strEmail, $bitAllow, $bitAbbreviate, $strAbout) )