1--TEST--
2mysqli_commit()
3--SKIPIF--
4<?php
5require_once('skipif.inc');
6require_once('skipifemb.inc');
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    if (false !== ($tmp = @$mysqli->commit())) {
25        printf("[013] Expecting false got %s/%s\n", gettype($tmp), $tmp);
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    if (!$mysqli->commit(0 , "*/ nonsense")) {
79        printf("[013] [%d] %s\n", $mysqli->errno, $mysqli->error);
80    }
81    if (!$mysqli->commit(0 , "tx_name ulf вендел")) {
82        printf("[014] [%d] %s\n", $mysqli->errno, $mysqli->error);
83    }
84    if (!$mysqli->commit(0 , "tx_name \t\n\r\b")) {
85        printf("[015] [%d] %s\n", $mysqli->errno, $mysqli->error);
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    if (false !== ($tmp = @$mysqli->commit())) {
94        printf("[017] Expecting false, got %s/%s\n", gettype($tmp), $tmp);
95    }
96
97    print "done!";
98?>
99--CLEAN--
100<?php
101    require_once("clean_table.inc");
102?>
103--EXPECTF--
104Warning: mysqli::commit(): Transaction name truncated. Must be only [0-9A-Za-z\-_=]+ in %s on line %d
105
106Warning: mysqli::commit(): Transaction name truncated. Must be only [0-9A-Za-z\-_=]+ in %s on line %d
107
108Warning: mysqli::commit(): Transaction name truncated. Must be only [0-9A-Za-z\-_=]+ in %s on line %d
109done!
110