MySQL Commands out of sync; you can not run this command now

4

I have a class Import (PHP) that serves to read XML files and to insert into the DB.

First of all I have the constructor of class Import that creates a new connection mysqli :

...
$this->mysqli = new mysqli( HOST, USER_NAME, PASSWORD, DATA_BASE );
mysqli_set_charset( $this->mysqli, CHARSET ) or die ( "ERROR: Connection fail!" );
...

In my reading function (from class Import ) I have this code:

...
$elems = $this->dom->getElementsByTagName( TAG_NAME );
foreach ( $elems as $elem )
{
   $elem1 = $elem->getElementsByTagName( TAG_ELEM1 );
   $elem2 = $elem->getElementsByTagName( TAG_ELEM2 );
   $elem3 = $elem->getElementsByTagName( TAG_ELEM3 );

   $sql2 = "SELECT 'elem4' FROM 'other' WHERE 'elem3'=?";
   $stmt2 = $this->mysqli->prepare( $sql2 ) ; //ERRO AQUI
   $stmt2->bind_param( "i", $elem3 );
   $stmt2->execute( );
   $stmt2->bind_result($elem4);
   $stmt2->store_result( );

   $sql = "INSERT INTO 'table'( 'elem1', 'elem2',  'elem4' ) VALUES ( ?, ?, ?)";
   $stmt = $this->mysqli->prepare( $sql ) ;
   $stmt->bind_param( "iss", $elem1, $elem2, $elem4 );
   $stmt->execute( );
   $stmt->store_result( );
}
...

When running I get this error (flagged in code):

  

(2014) Commands out of sync; you can not run this command now

I've read a few things in English, and $stmt->store_result( ); is supposed to solve this error, but that does not happen.

Note: Tables are to be created before being read: $this->mysqli->multi_query( $sql_create_all )

Any idea what it will be?

    
asked by anonymous 19.05.2014 / 15:26