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