0

Commands out of sync Error occur when executing this code.

foreach ($groupsId as $gpId) {

            $stmt = $db->query("CALL addUserToGroup(?,?)", array($userId, $gpId));
        $stmt->execute();


 }

This error occur

 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 

here's the stored procedure

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 ;

What should I do ???

palAlaa
  • 9,500
  • 33
  • 107
  • 166
  • Did it ever work? Is your data verified to be of correct type? It's a really simple looking prepared statement, although it looks like your variables are being passed backwards. Shouldn't `$gpId` be at position `0` in the array? – RockyFord May 01 '12 at 07:21
  • I try it locally and it works properly but the error occure when I work online. – palAlaa May 02 '12 at 06:19
  • I need a solution for this problem please :( – palAlaa May 08 '12 at 09:37
  • see if this has any info to help...http://stackoverflow.com/q/614671/1145086 – RockyFord May 09 '12 at 07:44
  • This is with PHP, my problem occurs with stored procedure.. – palAlaa May 10 '12 at 07:11
  • I understand, but your error is from the MySqli extension not from Mysql or Sql. Maybe try the PDO_Mysql extension and see if you get different results. – RockyFord May 10 '12 at 07:40

1 Answers1

0

Some thing like this

foreach ($groupsId as $gpId) {

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

Should work :)

Sergio
  • 34
  • 3