xref: /PHP-8.4/ext/mysqli/tests/transactions/014.phpt (revision 6a4031b8)
1--TEST--
2mysqli autocommit/commit/rollback with innodb with CACHE
3--EXTENSIONS--
4mysqli
5--SKIPIF--
6<?php
7require_once dirname(__DIR__) . "/test_setup/test_helpers.inc";
8mysqli_check_innodb_support_skip_test();
9?>
10--FILE--
11<?php
12require_once dirname(__DIR__) . "/test_setup/test_helpers.inc";
13
14    $link = default_mysqli_connect();
15
16    mysqli_autocommit($link, true);
17    mysqli_query($link,"CREATE TABLE test_transactions_14(a int, b varchar(10)) Engine=InnoDB");
18    mysqli_query($link, "INSERT INTO test_transactions_14 VALUES (1, 'foobar')");
19    mysqli_autocommit($link, false);
20
21    /* Modify data in DB */
22    mysqli_query($link, "DELETE FROM test_transactions_14");
23    mysqli_query($link, "INSERT INTO test_transactions_14 VALUES (2, 'egon')");
24
25    /* Attempt to rollback */
26    mysqli_rollback($link);
27
28    /* Check if rollback was successful */
29    $result = mysqli_query($link, "SELECT * FROM test_transactions_14");
30    printf("Num_of_rows=%d\n", mysqli_num_rows($result));
31    $row = mysqli_fetch_row($result);
32    mysqli_free_result($result);
33
34    var_dump($row);
35
36    /* Modify data in DB */
37    mysqli_query($link, "DELETE FROM test_transactions_14");
38    mysqli_query($link, "INSERT INTO test_transactions_14 VALUES (2, 'egon')");
39
40    /* Commit modifications */
41    mysqli_commit($link);
42
43    /* Check if commit was successful */
44    $result = mysqli_query($link, "SELECT * FROM test_transactions_14");
45    $row = mysqli_fetch_row($result);
46    mysqli_free_result($result);
47
48    var_dump($row);
49
50    mysqli_close($link);
51    print "done!";
52?>
53--CLEAN--
54<?php
55require_once dirname(__DIR__) . "/test_setup/test_helpers.inc";
56tear_down_table_on_default_connection('test_transactions_14');
57?>
58--EXPECT--
59Num_of_rows=1
60array(2) {
61  [0]=>
62  string(1) "1"
63  [1]=>
64  string(6) "foobar"
65}
66array(2) {
67  [0]=>
68  string(1) "2"
69  [1]=>
70  string(4) "egon"
71}
72done!
73