Jump to content

Odd behavior with mysqli's autocommit


effigy

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?

Thanks.

[code]<?php
$mysqli = new mysqli("localhost", "---", "---");

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

/* turn autocommit on */
$mysqli->autocommit(TRUE);

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

/* turn autocommit off */
$mysqli->autocommit(FALSE);

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

/* close connection */
$mysqli->close();
?> [/code]
Link to comment
https://forums.phpfreaks.com/topic/13773-odd-behavior-with-mysqlis-autocommit/
Share on other sites

Archived

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

×
×
  • Create New...

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.