1--TEST-- 2mysqli->autocommit() 3--EXTENSIONS-- 4mysqli 5--SKIPIF-- 6<?php 7 require_once 'connect.inc'; 8 9 if (!$link = @my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)) { 10 die(sprintf("skip Can't connect to MySQL Server - [%d] %s", mysqli_connect_errno(), mysqli_connect_error())); 11 } 12 13 if (!have_innodb($link)) 14 die(sprintf("skip Needs InnoDB support, [%d] %s", $link->errno, $link->error)); 15?> 16--FILE-- 17<?php 18 require_once 'connect.inc'; 19 20 $mysqli = new my_mysqli($host, $user, $passwd, $db, $port, $socket); 21 22 if (!is_bool($tmp = $mysqli->autocommit(true))) 23 printf("[002] Expecting boolean/any, got %s/%s\n", gettype($tmp), $tmp); 24 25 if (!$mysqli->query('SET AUTOCOMMIT = 0')) 26 printf("[003] [%d] %s\n", $mysqli->errno, $mysqli->error); 27 28 if (!$res = $mysqli->query('SELECT @@autocommit as auto_commit')) 29 printf("[004] [%d] %s\n", $mysqli->errno, $mysqli->error); 30 31 $tmp = $res->fetch_assoc(); 32 $res->free_result(); 33 if ($tmp['auto_commit']) 34 printf("[005] Cannot turn off autocommit\n"); 35 36 if (true !== ($tmp = $mysqli->autocommit( true))) 37 printf("[006] Expecting true, got %s/%s\n", gettype($tmp), $tmp); 38 39 if (!$res = $mysqli->query('SELECT @@autocommit as auto_commit')) 40 printf("[007] [%d] %s\n", $mysqli->errno, $mysqli->error); 41 $tmp = $res->fetch_assoc(); 42 $res->free_result(); 43 if (!$tmp['auto_commit']) 44 printf("[008] Cannot turn on autocommit\n"); 45 46 if (!$mysqli->query('DROP TABLE IF EXISTS test')) 47 printf("[009] [%d] %s\n", $mysqli->errno, $mysqli->error); 48 49 if (!$mysqli->query('CREATE TABLE test(id INT) ENGINE = InnoDB')) { 50 printf("[010] Cannot create test table, [%d] %s\n", $mysqli->errno, $mysqli->error); 51 } 52 53 if (!$mysqli->query('INSERT INTO test(id) VALUES (1)')) 54 printf("[011] [%d] %s\n", $mysqli->errno, $mysqli->error); 55 56 if (!$mysqli->query('ROLLBACK')) 57 printf("[012] [%d] %s\n", $mysqli->errno, $mysqli->error); 58 59 if (!$res = $mysqli->query('SELECT COUNT(*) AS num FROM test')) 60 printf("[013] [%d] %s\n", $mysqli->errno, $mysqli->error); 61 62 if ((!$tmp = $res->fetch_assoc()) || (1 != $tmp['num'])) 63 printf("[014] Expecting 1 row in table test, found %d rows. [%d] %s\n", 64 $tmp['num'], $mysqli->errno, $mysqli->error); 65 66 $res->free_result(); 67 68 if (!$mysqli->query('DROP TABLE IF EXISTS test')) 69 printf("[015] [%d] %s\n", $mysqli->errno, $mysqli->error); 70 71 if (!$mysqli->query('SET AUTOCOMMIT = 1')) 72 printf("[016] [%d] %s\n", $mysqli->errno, $mysqli->error); 73 74 if (!$res = $mysqli->query('SELECT @@autocommit as auto_commit')) 75 printf("[017] [%d] %s\n", $mysqli->errno, $mysqli->error); 76 77 $tmp = $res->fetch_assoc(); 78 $res->free_result(); 79 if (!$tmp['auto_commit']) 80 printf("[018] Cannot turn on autocommit\n"); 81 82 if (true !== ($tmp = $mysqli->autocommit( false))) 83 printf("[019] Expecting true, got %s/%s\n", gettype($tmp), $tmp); 84 85 if (!$mysqli->query('CREATE TABLE test(id INT) ENGINE = InnoDB')) { 86 printf("[020] Cannot create test table, [%d] %s\n", $mysqli->errno, $mysqli->error); 87 } 88 89 if (!$mysqli->query('INSERT INTO test(id) VALUES (1)')) 90 printf("[021] [%d] %s\n", $mysqli->errno, $mysqli->error); 91 92 if (!$mysqli->query('ROLLBACK')) 93 printf("[022] [%d] %s\n", $mysqli->errno, $mysqli->error); 94 95 if (!$res = $mysqli->query('SELECT COUNT(*) AS num FROM test')) 96 printf("[023] [%d] %s\n", $mysqli->errno, $mysqli->error); 97 $tmp = $res->fetch_assoc(); 98 if (0 != $tmp['num']) 99 printf("[24] Expecting 0 rows in table test, found %d rows\n", $tmp['num']); 100 $res->free_result(); 101 102 if (!$mysqli->query('INSERT INTO test(id) VALUES (1)')) 103 printf("[025] [%d] %s\n", $mysqli->errno, $mysqli->error); 104 105 if (!$mysqli->query('COMMIT')) 106 printf("[025] [%d] %s\n", $mysqli->errno, $mysqli->error); 107 108 if (!$res = $mysqli->query('SELECT COUNT(*) AS num FROM test')) 109 printf("[027] [%d] %s\n", $mysqli->errno, $mysqli->error); 110 111 if ((!$tmp = $res->fetch_assoc()) || (1 != $tmp['num'])) 112 printf("[028] Expecting 1 row in table test, found %d rows. [%d] %s\n", 113 $tmp['num'], $mysqli->errno, $mysqli->error); 114 $res->free_result(); 115 116 if (!$mysqli->query('DROP TABLE IF EXISTS test')) 117 printf("[029] [%d] %s\n", $mysqli->errno, $mysqli->error); 118 119 $mysqli->close(); 120 121 try { 122 $mysqli->autocommit(false); 123 } catch (Error $exception) { 124 echo $exception->getMessage() . "\n"; 125 } 126 127 print "done!"; 128?> 129--CLEAN-- 130<?php 131require_once 'clean_table.inc'; 132?> 133--EXPECT-- 134my_mysqli object is already closed 135done! 136