这是我的存储过程:
DELIMITER $$
CREATE PROCEDURE `insert_request_info`(in request_type text, in adequeate bool, in status bool, in email bool, in pickup bool, in comments text,
in request_date timestamp, in pickup_date timestamp, in email_date timestamp, in psid varchar(40), in dso_id varchar(40), out last_id real)
BEGIN
insert into request_info values(DEFAULT, request_type, adequeate, status, email, pickup, comments, request_date, pickup_date, email_date, psid, dso_id);
SET last_id = LAST_INSERT_ID();
END
我试图以下列方式执行此存储过程:
$request_info_query = "CALL insert_request_info('invitation', false, false, false, false, '', Now(), timestamp(0), timestamp(0), $student_psid, null, @out);SELECT @out;";
$result = mysql_query($request_info_query, $con);
当我执行上面的代码时,它给出了以下错误:
您的SQL语法有错误;检查手册 对应于您的MySQL服务器版本,以便使用正确的语法 靠近' SELECT @ out'在线1CALL insert_request_info('邀请', false,false,false,false,'',Now(),timestamp(0),timestamp(0),12, null,@ out); SELECT @out;
我检查了其他解决方案,很多人都做了同样的事情。但是我还有错误,有什么帮助吗?
答案 0 :(得分:0)
在PHP中,您只能一次执行一个语句。使用两个不同的调用来执行此代码。 e.g:
// Insert info
$insert_query = "CALL insert_request_info('invitation', false, false, false, false, '', Now(), timestamp(0), timestamp(0), $student_psid, null, @out);";
$insert_result = mysql_query($insert_query, $con);
// Get query result
$request_info_query = "SELECT @out;";
$result = mysql_query($request_info_query, $con);
答案 1 :(得分:0)
mysql_query
will only send one query at at time,不推荐使用mysql
扩展程序;您应该使用改进的扩展程序mysqli
,更具体地说是函数mysqli_multi_query
。
话虽如此,我相信向它看起来像mysql_query
发送多个查询只会在第一个之后忽略查询,因此您不应该从MySQL看到该错误。mysql_query
中的分号会导致此错误。您还应该考虑在定义过程后明确更改分隔符,以避免将来出现错误。
DELIMITER $$
CREATE PROCEDURE ...
END$$
DELIMITER ;