xref: /PHP-7.1/ext/mysqli/tests/mysqli_commit.phpt (revision 113213f0)
1--TEST--
2mysqli_commit()
3--SKIPIF--
4<?php
5require_once('skipif.inc');
6require_once('skipifemb.inc');
7require_once('skipifconnectfailure.inc');
8
9require_once('connect.inc');
10if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))
11	die(sprintf("Cannot connect, [%d] %s", mysqli_connect_errno(), mysqli_connect_error()));
12
13if (!have_innodb($link))
14	die(sprintf("Needs InnoDB support, [%d] %s", $link->errno, $link->error));
15?>
16--FILE--
17<?php
18	require_once("connect.inc");
19
20	$tmp    = NULL;
21	$link   = NULL;
22
23	if (!is_null($tmp = @mysqli_commit()))
24		printf("[001] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
25
26	if (!is_null($tmp = @mysqli_commit($link)))
27		printf("[002] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
28
29	if (!is_null($tmp = @mysqli_commit($link, $link)))
30		printf("[003] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
31
32	if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))
33		printf("[004] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
34			$host, $user, $db, $port, $socket);
35
36	if (true !== ($tmp = mysqli_autocommit($link, false)))
37		printf("[005] Cannot turn off autocommit, expecting true, got %s/%s\n", gettype($tmp), $tmp);
38
39	if (!mysqli_query($link, 'DROP TABLE IF EXISTS test'))
40		printf("[006] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
41
42	if (!mysqli_query($link, 'CREATE TABLE test(id INT) ENGINE = InnoDB'))
43		printf("[007] Cannot create test table, [%d] %s\n", mysqli_errno($link), mysqli_error($link));
44
45	if (!mysqli_query($link, 'INSERT INTO test(id) VALUES (1)'))
46		printf("[008] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
47
48	$tmp = mysqli_commit($link);
49	if ($tmp !== true)
50		printf("[009] Expecting boolean/true, got %s/%s\n", gettype($tmp), $tmp);
51
52	if (!mysqli_query($link, 'ROLLBACK'))
53		printf("[010] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
54
55	if (!$res = mysqli_query($link, 'SELECT COUNT(*) AS num FROM test'))
56		printf("[011] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
57	$tmp = mysqli_fetch_assoc($res);
58	if (1 != $tmp['num'])
59		printf("[12] Expecting 1 row in table test, found %d rows\n", $tmp['num']);
60	mysqli_free_result($res);
61
62	if (!mysqli_query($link, 'DROP TABLE IF EXISTS test'))
63		printf("[013] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
64
65	mysqli_close($link);
66
67	if (NULL !== ($tmp = @mysqli_commit($link)))
68		printf("[014] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
69
70	print "done!";
71?>
72--CLEAN--
73<?php
74	require_once("clean_table.inc");
75?>
76--EXPECTF--
77done!
78