<?php
$serverName = "localhost";
$username = "root";
$password = "";
$Database = "database";
$con = mysqli_connect($serverName, $username, $password, $Database);
if (mysqli_connect_errno()) {
echo "PLEASE IMPORT THE DATABASE";
}
try {
mysqli_autocommit($con,FALSE);
for ($i=1; $i < 100; $i++) {
$Query = "INSERT INTO `test`(`id`, `name`, `version`) VALUES ('".$i."','name".$i."','version".$i."')";
$Result = mysqli_query($con,$Query);
if($Result==false){
throw new Exception(" Error Found at index " . $i);
}
}
echo "calling commit";
mysqli_commit($con);
}
catch(Exception $e) {
echo "calling rollback";
mysqli_rollback($con);
echo 'Message: ' .$e->getMessage();
}
I have created a test file for testing rollback(). In test table id
as primary key.
First time i executed this file, so 99 records(id from 1 to 99) is inserted.
result :
calling commit
Now i removed pk value 1,2,3 from test table. Now the table has 96 records(id from 4 to 99) if i run the file aging
result :
calling rollbackMessage: Error Found at index 4
But the pk value 1,2,3 is stored in the table even i call the rollback(). Now the table has 99 records(id from 1 to 99) Why it is happening? Please help me.