Mysqli准备错误:命令不同步;

时间:2012-04-30 10:07:32

标签: zend-framework stored-procedures

命令不同步执行此代码时出错。

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 ;

我该怎么做???

1 个答案:

答案 0 :(得分:0)

有点像这样

foreach ($groupsId as $gpId) {

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

应该工作:)