Hi all,
I am new to the mysqli, I'm trying to create this function to rollback some queries if one of them has error.
however I found that the mysqi->rollback function doesn't rollback my query. please help.
here are the code I coded:
function executeSqlStatment($sql_statment_array)
{
$mysqli = new mysqli("xxx", "xxx", "xxx", "xxx" );
/* check connection */
if (mysqli_connect_errno())
{
writeLog("prepareSqlStatment", "Connect failed: ".mysqli_connect_error());
exit();
}
$is_query_error = false;
/* disable autocommit */
$mysqli->autocommit(FALSE);
for($i = 0; $i < count($sql_statment_array); $i++)
{
writeLog("prepareSqlStatment", $sql_statment_array[$i]);
if (!$mysqli->query($sql_statment_array[$i]))
{
$is_query_error = true;
writeLog("prepareSqlStatment", "Error: ".$mysqli->error);
}
}
if ($is_query_error)
{
$mysqli->rollback();
$mysqli->close();
writeLog("prepareSqlStatment", "Error: Rollback ". count($sql_statment_array) ." Statement ");
return false;
}
else
{
$mysqli->commit();
$mysqli->close();
return true;
}
}
THANKS GUYS : )
mysqli->rollback problem
Moderator: General Moderators