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