xref: /PHP-8.2/ext/mysqli/tests/015.phpt (revision 05ed3b77)
1--TEST--
2mysqli autocommit/commit/rollback with innodb
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}
11
12if (!have_innodb($link)) {
13    die(sprintf("skip Needs InnoDB support, [%d] %s", $link->errno, $link->error));
14}
15?>
16--FILE--
17<?php
18    require_once "connect.inc";
19
20    $link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket);
21    if (!$link)
22        printf("[001] Cannot connect, [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
23
24    if (!mysqli_select_db($link, $db))
25        printf("[002] Cannot select DB '%s', [%d] %s\n", $db,
26            mysqli_errno($link), mysqli_error($link));
27
28    if (!mysqli_autocommit($link, TRUE))
29        printf("[003] Cannot turn on autocommit mode, [%d] %s\n",
30            mysqli_errno($link), mysqli_error($link));
31
32    if (!mysqli_query($link,"DROP TABLE IF EXISTS test") ||
33        !mysqli_query($link,"CREATE TABLE test(a int, b varchar(10)) Engine=InnoDB") ||
34        !mysqli_query($link, "INSERT INTO test VALUES (1, 'foobar')"))
35        printf("[004] Cannot create test data, [%d] %s\n",
36            mysqli_errno($link), mysqli_error($link));
37
38    if (!mysqli_autocommit($link, FALSE))
39        printf("[005] Cannot turn off autocommit mode, [%d] %s\n",
40            mysqli_errno($link), mysqli_error($link));
41
42    if (!mysqli_query($link, "DELETE FROM test") ||
43            !mysqli_query($link, "INSERT INTO test VALUES (2, 'egon')"))
44        printf("[006] Cannot modify test data, [%d] %s\n",
45            mysqli_errno($link), mysqli_error($link));
46
47    if (!mysqli_rollback($link))
48        printf("[007] Cannot call rollback, [%d] %s\n",
49            mysqli_errno($link), mysqli_error($link));
50
51    $result = mysqli_query($link, "SELECT SQL_NO_CACHE * FROM test");
52    if (!$result)
53        printf("[008] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
54    $row = mysqli_fetch_row($result);
55    mysqli_free_result($result);
56
57    var_dump($row);
58
59    if (!mysqli_query($link, "DELETE FROM test") ||
60            !mysqli_query($link, "INSERT INTO test VALUES (2, 'egon')"))
61        printf("[009] Cannot modify test data, [%d] %s\n",
62            mysqli_errno($link), mysqli_error($link));
63
64    mysqli_commit($link);
65
66    $result = mysqli_query($link, "SELECT * FROM test");
67    if (!$result)
68        printf("[010] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
69    $row = mysqli_fetch_row($result);
70    mysqli_free_result($result);
71
72    var_dump($row);
73
74    mysqli_query($link, "DROP TABLE IF EXISTS test");
75    mysqli_close($link);
76    print "done!";
77?>
78--CLEAN--
79<?php
80require_once "clean_table.inc";
81?>
82--EXPECT--
83array(2) {
84  [0]=>
85  string(1) "1"
86  [1]=>
87  string(6) "foobar"
88}
89array(2) {
90  [0]=>
91  string(1) "2"
92  [1]=>
93  string(4) "egon"
94}
95done!
96