1--TEST--
2mysqli_commit()
3--EXTENSIONS--
4mysqli
5--SKIPIF--
6<?php
7require_once 'connect.inc';
8if (!$link = @my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))
9    die(sprintf("skip Can't connect to MySQL Server - [%d] %s", mysqli_connect_errno(), mysqli_connect_error()));
10
11if (!have_innodb($link))
12    die(sprintf("skip Needs InnoDB support, [%d] %s", $link->errno, $link->error));
13?>
14--FILE--
15<?php
16    require_once 'connect.inc';
17
18    $mysqli = new mysqli();
19    try {
20        $mysqli->commit();
21    } catch (Error $exception) {
22        echo $exception->getMessage() . "\n";
23    }
24
25    $mysqli = new my_mysqli($host, $user, $passwd, $db, $port, $socket);
26
27    if (true !== ($tmp = $mysqli->commit())) {
28        printf("[002] Expecting boolean/true got %s/%s\n", gettype($tmp), $tmp);
29    }
30
31    if (true !== ($tmp = $mysqli->autocommit(false))) {
32        printf("[003] Cannot turn off autocommit, expecting true, got %s/%s\n", gettype($tmp), $tmp);
33    }
34
35    if (!$mysqli->query('DROP TABLE IF EXISTS test')) {
36        printf("[004] [%d] %s\n", $mysqli->errno, $mysqli->error);
37    }
38
39    if (!$mysqli->query('CREATE TABLE test(id INT) ENGINE = InnoDB')) {
40        printf("[005] Cannot create test table, [%d] %s\n", $mysqli->errno, $mysqli->error);
41    }
42
43    if (!$mysqli->query('INSERT INTO test(id) VALUES (1)')) {
44        printf("[006] [%d] %s\n", $mysqli->errno, $mysqli->error);
45    }
46
47    $tmp = $mysqli->commit();
48    if ($tmp !== true) {
49        printf("[007] Expecting boolean/true, got %s/%s\n", gettype($tmp), $tmp);
50    }
51
52    if (!$mysqli->query('ROLLBACK'))
53        printf("[008] [%d] %s\n", $mysqli->errno, $mysqli->error);
54
55    if (!$res = $mysqli->query('SELECT COUNT(*) AS num FROM test')) {
56        printf("[009] [%d] %s\n", $mysqli->errno, $mysqli->error);
57    }
58
59    $tmp = $res->fetch_assoc();
60    if (1 != $tmp['num']) {
61        printf("[010] Expecting 1 row in table test, found %d rows\n", $tmp['num']);
62    }
63    $res->free();
64
65    if (!$mysqli->query('DROP TABLE IF EXISTS test')) {
66        printf("[011] [%d] %s\n", $mysqli->errno, $mysqli->error);
67    }
68
69    if (!$mysqli->commit(0 , "tx_name0123")) {
70        printf("[012] [%d] %s\n", $mysqli->errno, $mysqli->error);
71    }
72
73    var_dump($mysqli->commit(0 , "*/ nonsense"));
74
75    var_dump($mysqli->commit(0 , "tx_name ulf вендел"));
76
77    var_dump($mysqli->commit(0 , "tx_name \t\n\r\b"));
78
79    if (!$mysqli->commit(MYSQLI_TRANS_COR_AND_CHAIN | MYSQLI_TRANS_COR_NO_RELEASE , "tx_name")) {
80        printf("[016] [%d] %s\n", $mysqli->errno, $mysqli->error);
81    }
82
83    $mysqli->close();
84
85    try {
86        $mysqli->commit();
87    } catch (Error $exception) {
88        echo $exception->getMessage() . "\n";
89    }
90
91    print "done!";
92?>
93--CLEAN--
94<?php
95require_once 'clean_table.inc';
96?>
97--EXPECTF--
98mysqli object is not fully initialized
99
100Warning: mysqli::commit(): Transaction name has been truncated, since it can only contain the A-Z, a-z, 0-9, "\", "-", "_", and "=" characters in %s on line %d
101bool(true)
102
103Warning: mysqli::commit(): Transaction name has been truncated, since it can only contain the A-Z, a-z, 0-9, "\", "-", "_", and "=" characters in %s on line %d
104bool(true)
105
106Warning: mysqli::commit(): Transaction name has been truncated, since it can only contain the A-Z, a-z, 0-9, "\", "-", "_", and "=" characters in %s on line %d
107bool(true)
108my_mysqli object is already closed
109done!
110