I am reading an XML file and at the same time I insert the records into the DB.
My code looks like this:
foreach($itens as $item)
{
...
if ( ! $stmt_insert_item->execute ( ) )
{
if ( $this->mysqli->errno == ER_DUP_ENTRY ) // se for uma entrada duplicada
continue;
else
{
echo "Execute failed: (" . $this->mysqli->errno . ") " . $this->mysqli->error;
return false;
}
}
}
What is happening to me is that whenever I have a duplicate it always enters else
, but it prints errno with the correct flag (1062) which is equal to ER_DUP_ENTRY.
My question is Is there a problem to run and only then check to see if it is duplicated and moving forward? Or does the connection close after the error?