Jump to content


This topic is now archived and is closed to further replies.


Odd behavior with mysqli's autocommit

Recommended Posts

The code for this was taken from the manual page for mysqli_autocommit, with an additional test added to turn autocommit off.

I am testing this on 2 boxes:
1. Windows, PHP 5.1.2, MySQL 5.0.18
2. Unix, PHP 5.1.4, MySQL 5.0.20a

The code gives the following results:
1. Windows: "Autocommit is 1 Autocommit is 0"
2. Unix: "Autocommit is 1 Autocommit is 1"

Interestingly enough, if I replace [b]$mysqli->autocommit(FALSE);[/b] with [b]$mysqli->query('set autocommit = 0');[/b] it works.

Has anyone seen this before, or worked with autocommit?


$mysqli = new mysqli("localhost", "---", "---");

if (mysqli_connect_errno()) {
  printf("Connect failed: %s\n", mysqli_connect_error());

/* turn autocommit on */

if ($result = $mysqli->query("SELECT @@autocommit")) {
  $row = $result->fetch_row();
  printf("Autocommit is %s\n", $row[0]);

/* turn autocommit off */

if ($result = $mysqli->query("SELECT @@autocommit")) {
  $row = $result->fetch_row();
  printf("Autocommit is %s\n", $row[0]);

/* close connection */
?> [/code]

Share this post

Link to post
Share on other sites


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.