xref: /PHP-8.3/ext/mysqli/tests/mysqli_commit.phpt (revision a21edc52)
1--TEST--
2mysqli_commit()
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
11if (!have_innodb($link))
12    die(sprintf("skip Needs InnoDB support, [%d] %s", $link->errno, $link->error));
13?>
14--FILE--
15<?php
16    require_once 'connect.inc';
17
18    if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))
19        printf("[004] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
20            $host, $user, $db, $port, $socket);
21
22    if (true !== ($tmp = mysqli_autocommit($link, false)))
23        printf("[005] Cannot turn off autocommit, expecting true, got %s/%s\n", gettype($tmp), $tmp);
24
25    if (!mysqli_query($link, 'DROP TABLE IF EXISTS test'))
26        printf("[006] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
27
28    if (!mysqli_query($link, 'CREATE TABLE test(id INT) ENGINE = InnoDB'))
29        printf("[007] Cannot create test table, [%d] %s\n", mysqli_errno($link), mysqli_error($link));
30
31    if (!mysqli_query($link, 'INSERT INTO test(id) VALUES (1)'))
32        printf("[008] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
33
34    $tmp = mysqli_commit($link);
35    if ($tmp !== true)
36        printf("[009] Expecting boolean/true, got %s/%s\n", gettype($tmp), $tmp);
37
38    if (!mysqli_query($link, 'ROLLBACK'))
39        printf("[010] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
40
41    if (!$res = mysqli_query($link, 'SELECT COUNT(*) AS num FROM test'))
42        printf("[011] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
43    $tmp = mysqli_fetch_assoc($res);
44    if (1 != $tmp['num'])
45        printf("[12] Expecting 1 row in table test, found %d rows\n", $tmp['num']);
46    mysqli_free_result($res);
47
48    if (!mysqli_query($link, 'DROP TABLE IF EXISTS test'))
49        printf("[013] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
50
51    mysqli_close($link);
52
53    try {
54        mysqli_commit($link);
55    } catch (Error $exception) {
56        echo $exception->getMessage() . "\n";
57    }
58
59    print "done!";
60?>
61--CLEAN--
62<?php
63require_once 'clean_table.inc';
64?>
65--EXPECT--
66mysqli object is already closed
67done!
68