5
I am reading an XML file and at the same time insert the entries in the BD.
My code is 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’s happening to me is that every time I have a duplicate, it always goes into else
, but prints Errno with the correct flag (1062) which is equal to ER_DUP_ENTRY.
My question is there is problem to run and only then check if it is duplicated and advance? Or the connection closes after the error?
You use storade Procedure?
– abfurlan
For security work with Primary Keys or Unique Keys.
– Motta
@abfurlan no, it’s direct even.
– Jorge B.
@Motta and work, that’s the case, gives duplicate key BD error...
– Jorge B.
@Jorge B. , the idea is this, make a mistake.
– Motta
@Motta I know, but read my question in bold, does the connection close after the error? Is that I have no idea why but this code
if ( $this->mysqli->errno == ER_DUP_ENTRY )
is always false even if Errno = 1062, and I have no idea why...– Jorge B.
@Jorge B. I can’t say.
– Motta
Before the
if
comparison makesvar_dump($this->mysqli->errno);
to see the type/value you are receiving... may give you some insight into the problem. The same applies toER_DUP_ENTRY
.– Zuul
@Zuul They’re both of the same value.
– Jorge B.