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    $tmp    = NULL;
19    $link   = NULL;
20
21    $mysqli = new mysqli();
22    try {
23        $mysqli->commit();
24    } catch (Error $exception) {
25        echo $exception->getMessage() . "\n";
26    }
27
28    if (!$mysqli = new my_mysqli($host, $user, $passwd, $db, $port, $socket)) {
29        printf("[001] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
30            $host, $user, $db, $port, $socket);
31    }
32
33    if (true !== ($tmp = $mysqli->commit())) {
34        printf("[002] Expecting boolean/true got %s/%s\n", gettype($tmp), $tmp);
35    }
36
37    if (true !== ($tmp = $mysqli->autocommit(false))) {
38        printf("[003] Cannot turn off autocommit, expecting true, got %s/%s\n", gettype($tmp), $tmp);
39    }
40
41    if (!$mysqli->query('DROP TABLE IF EXISTS test')) {
42        printf("[004] [%d] %s\n", $mysqli->errno, $mysqli->error);
43    }
44
45    if (!$mysqli->query('CREATE TABLE test(id INT) ENGINE = InnoDB')) {
46        printf("[005] Cannot create test table, [%d] %s\n", $mysqli->errno, $mysqli->error);
47    }
48
49    if (!$mysqli->query('INSERT INTO test(id) VALUES (1)')) {
50        printf("[006] [%d] %s\n", $mysqli->errno, $mysqli->error);
51    }
52
53    $tmp = $mysqli->commit();
54    if ($tmp !== true) {
55        printf("[007] Expecting boolean/true, got %s/%s\n", gettype($tmp), $tmp);
56    }
57
58    if (!$mysqli->query('ROLLBACK'))
59        printf("[008] [%d] %s\n", $mysqli->errno, $mysqli->error);
60
61    if (!$res = $mysqli->query('SELECT COUNT(*) AS num FROM test')) {
62        printf("[009] [%d] %s\n", $mysqli->errno, $mysqli->error);
63    }
64
65    $tmp = $res->fetch_assoc();
66    if (1 != $tmp['num']) {
67        printf("[010] Expecting 1 row in table test, found %d rows\n", $tmp['num']);
68    }
69    $res->free();
70
71    if (!$mysqli->query('DROP TABLE IF EXISTS test')) {
72        printf("[011] [%d] %s\n", $mysqli->errno, $mysqli->error);
73    }
74
75    if (!$mysqli->commit(0 , "tx_name0123")) {
76        printf("[012] [%d] %s\n", $mysqli->errno, $mysqli->error);
77    }
78
79    var_dump($mysqli->commit(0 , "*/ nonsense"));
80
81    var_dump($mysqli->commit(0 , "tx_name ulf вендел"));
82
83    var_dump($mysqli->commit(0 , "tx_name \t\n\r\b"));
84
85    if (!$mysqli->commit(MYSQLI_TRANS_COR_AND_CHAIN | MYSQLI_TRANS_COR_NO_RELEASE , "tx_name")) {
86        printf("[016] [%d] %s\n", $mysqli->errno, $mysqli->error);
87    }
88
89    $mysqli->close();
90
91    try {
92        $mysqli->commit();
93    } catch (Error $exception) {
94        echo $exception->getMessage() . "\n";
95    }
96
97    print "done!";
98?>
99--CLEAN--
100<?php
101require_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