xref: /PHP-8.3/ext/mysqli/tests/014.phpt (revision a21edc52)
1--TEST--
2mysqli autocommit/commit/rollback
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    $link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket);
20
21    if (!mysqli_autocommit($link, TRUE))
22        printf("[001] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
23
24    if (!mysqli_query($link, "DROP TABLE IF EXISTS test"))
25        printf("[002] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
26
27    if (!mysqli_query($link, "CREATE TABLE test(a int, b varchar(10)) engine=InnoDB"))
28        printf("[003] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
29
30    if (!mysqli_query($link, "INSERT INTO test VALUES (1, 'foobar')"))
31        printf("[004] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
32
33    if (!mysqli_autocommit($link, FALSE))
34        printf("[005] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
35
36    if (!mysqli_query($link, "DELETE FROM test"))
37        printf("[006] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
38
39    if (!mysqli_query($link, "INSERT INTO test VALUES (2, 'egon')"))
40        printf("[007] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
41
42    if (!mysqli_rollback($link))
43        printf("[008] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
44
45    if (!$result = mysqli_query($link, "SELECT * FROM test"))
46        printf("[009] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
47
48    printf("Num_of_rows=%d\n", mysqli_num_rows($result));
49    if (!$row = mysqli_fetch_row($result))
50        printf("[010] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
51
52    mysqli_free_result($result);
53
54    var_dump($row);
55
56    if (!mysqli_query($link, "DELETE FROM test"))
57        printf("[011] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
58
59    if (!mysqli_query($link, "INSERT INTO test VALUES (2, 'egon')"))
60        printf("[012] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
61
62    if (!mysqli_commit($link))
63        printf("[012] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
64
65    if (!$result = mysqli_query($link, "SELECT * FROM test"))
66        printf("[013] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
67
68    if (!$row = mysqli_fetch_row($result))
69        printf("[014] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
70
71    mysqli_free_result($result);
72
73    var_dump($row);
74
75    mysqli_query($link, "DROP TABLE IF EXISTS test");
76    mysqli_close($link);
77    print "done!";
78?>
79--CLEAN--
80<?php
81require_once 'clean_table.inc';
82?>
83--EXPECT--
84Num_of_rows=1
85array(2) {
86  [0]=>
87  string(1) "1"
88  [1]=>
89  string(6) "foobar"
90}
91array(2) {
92  [0]=>
93  string(1) "2"
94  [1]=>
95  string(4) "egon"
96}
97done!
98