0

I am trying to test the php mysqli autocommit function. I have a very basic example below. When I run this script the query executes and is inserted in the db. Why does this happen, I have commented out the commit portion and therefore would not expect the query to insert into the db.

$db_con=mysqli_connect($server, $dbuname, $dbpassw, $database);
mysqli_autocommit($db_con,FALSE);

mysqli_begin_transaction($db_con);
$sql="INSERT INTO table (a, b, c) VALUES ";
$sql=$sql."('1','2','3')"; 
mysqli_query($db_con,$sql);
//mysqli_commit($mysqli);

Thanks

Dharman
  • 30,962
  • 25
  • 85
  • 135
the_big_blackbox
  • 1,056
  • 2
  • 15
  • 35
  • Tip: A lot of problems can be detected and resolved by [enabling exceptions in `mysqli`](https://stackoverflow.com/questions/14578243/turning-query-errors-to-exceptions-in-mysqli) so errors resulting from simple mistakes made aren’t easily ignored. Without exceptions you must pay close attention to return values, many of these indicate problems you must resolve or report to the user. Exceptions allow for more sophisticated flow control as they can “bubble up” to other parts of your code where it’s more convenient to handle them. – tadman Apr 21 '20 at 19:20
  • thanks I enable it now, no exceptions – the_big_blackbox Apr 21 '20 at 19:24
  • Did you try rolling back explicitly? – tadman Apr 21 '20 at 19:24
  • I tried now and it still does the insert – the_big_blackbox Apr 21 '20 at 19:29
  • 2
    What type of table do you use? Innodb or myisam? – Shadow Apr 21 '20 at 19:37
  • I think thats the issue thanks, the tables myisam and db is innodb – the_big_blackbox Apr 21 '20 at 19:40
  • 1
    Yeah, MyISAM doesn't support transactions, it just pretends it does. It's also not worth using for a multitude of important reasons, so be sure everything is InnoDB. – tadman Apr 21 '20 at 21:11

0 Answers0