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