命令不同步执行此代码时出错。
foreach ($groupsId as $gpId) {
$stmt = $db->query("CALL addUserToGroup(?,?)", array($userId, $gpId));
$stmt->execute();
}
发生此错误
Db_Statement_Mysqli_Exception' with message 'Mysqli prepare error: Commands out of sync; you can't run this command now' in /var/www/html/zend/Zend/Db/Statement/Mysqli.php:77 Stack trace: #0
这是存储过程
DELIMITER //
CREATE PROCEDURE addUserToGroup(IN groupId INT(11),IN userId INT(11) )
BEGIN
insert into `group_users`(`group_id`,`user_id`) values(groupId ,userId );
END //
DELIMITER ;
我该怎么做???
答案 0 :(得分:0)
有点像这样
foreach ($groupsId as $gpId) {
$stmt = $db->query("CALL addUserToGroup(?,?)", array($userId, $gpId));
$result = $stmt->execute();
//or $result = $query->fetchAll();
$stmt->closeCursor();
}
应该工作:)