5
I have a class Import
(PHP) which is used to read XML files and insert into the BD.
First I got the class builder 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 (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 executing I have this error (flagged in the code):
(2014) Commands out of Sync; you can’t run this command now
I’ve read some things in English and supposedly the $stmt->store_result( );
would solve that mistake, but that does not happen.
Note: Tables are being created before reading: $this->mysqli->multi_query( $sql_create_all )
Any idea what it will be?
$sql
calls a store Previous?– rray
@lost edited and put the query
– Jorge B.
I had forgotten of this part that may be important.
– Jorge B.