0

执行此代码时发生命令不同步错误。

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 ;

我应该怎么办 ???

4

1 回答 1

0

像这样的东西

foreach ($groupsId as $gpId) {

    $stmt = $db->query("CALL addUserToGroup(?,?)", array($userId, $gpId));
    $result = $stmt->execute();
    //or $result = $query->fetchAll();
    $stmt->closeCursor();
}

应该管用 :)

于 2014-08-08T15:02:02.753 回答