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