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	$mysqli = new mysqli();
24	if (!is_null($tmp = @$mysqli->commit()))
25		printf("[013] Expecting NULL got %s/%s\n", gettype($tmp), $tmp);
26
27	if (!$mysqli = new my_mysqli($host, $user, $passwd, $db, $port, $socket))
28		printf("[001] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
29			$host, $user, $db, $port, $socket);
30
31	if (!is_null($tmp = @$mysqli->commit($link)))
32		printf("[002] Expecting NULL/NULL, got %s/%s, [%d] %s\n",
33			gettype($tmp), $tmp, $mysqli->errno, $mysqli->error);
34
35	if (true !== ($tmp = $mysqli->commit()))
36		printf("[014] Expecting boolean/true got %s/%s\n", gettype($tmp), $tmp);
37
38	if (true !== ($tmp = $mysqli->autocommit(false)))
39		printf("[003] Cannot turn off autocommit, expecting true, got %s/%s\n", gettype($tmp), $tmp);
40
41	if (!$mysqli->query('DROP TABLE IF EXISTS test'))
42		printf("[004] [%d] %s\n", $mysqli->errno, $mysqli->error);
43
44	if (!$mysqli->query('CREATE TABLE test(id INT) ENGINE = InnoDB'))
45		printf("[005] Cannot create test table, [%d] %s\n", $mysqli->errno, $mysqli->error);
46
47	if (!$mysqli->query('INSERT INTO test(id) VALUES (1)'))
48		printf("[006] [%d] %s\n", $mysqli->errno, $mysqli->error);
49
50	$tmp = $mysqli->commit();
51	if ($tmp !== true)
52		printf("[007] Expecting boolean/true, got %s/%s\n", gettype($tmp), $tmp);
53
54	if (!$mysqli->query('ROLLBACK'))
55		printf("[008] [%d] %s\n", $mysqli->errno, $mysqli->error);
56
57	if (!$res = $mysqli->query('SELECT COUNT(*) AS num FROM test'))
58		printf("[009] [%d] %s\n", $mysqli->errno, $mysqli->error);
59	$tmp = $res->fetch_assoc();
60	if (1 != $tmp['num'])
61		printf("[010] Expecting 1 row in table test, found %d rows\n", $tmp['num']);
62	$res->free();
63
64	if (!$mysqli->query('DROP TABLE IF EXISTS test'))
65		printf("[011] [%d] %s\n", $mysqli->errno, $mysqli->error);
66
67	$mysqli->close();
68
69	if (NULL !== ($tmp = @$mysqli->commit()))
70		printf("[012] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
71
72	print "done!";
73?>
74--CLEAN--
75<?php
76	require_once("clean_table.inc");
77?>
78--EXPECTF--
79done!