I'm facing a strange issue with a transaction, this is the code:
$mysqli = $this->getMysqli();
//Avoid Autocommitting
$mysqli->autocommit(FALSE);
$mysqli->begin_transaction();
$insertStatment = $mysqli->prepare('INSERT INTO '.$this->table.' (name, applied_at) VALUES (?, NOW())');
try
{
$mysqli->multi_query($sql);
$insertStatment->bind_param('s', $name);
$insertStatment->execute();
$insertStatment->close();
$mysqli->commit();
$mysqli->close();
return TRUE;
}
catch (Exception $e)
{
$mysqli->rollBack();
return $e->getMessage();
}
The $insertStatement gets completely ignored by the commit(). If I comment this line:
$mysqli->multi_query($sql);
It works perfectly, is there any issue when mixing prepared statements and multi_query?
I need multi query because the $sql
variable contains multiple ;
separated sql statements. Is there any way to prevent this issue?