1--TEST--
2mysqli_savepoint()
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("skip Cannot connect, [%d] %s", mysqli_connect_errno(), mysqli_connect_error()));
12
13if (!have_innodb($link))
14    die(sprintf("skip Needs InnoDB support, [%d] %s", $link->errno, $link->error));
15?>
16--FILE--
17<?php
18    require_once("connect.inc");
19     /* {{{ proto bool mysqli_savepoint(object link, string name) */
20    $tmp    = NULL;
21    $link   = NULL;
22
23    if (!is_null($tmp = @mysqli_savepoint()))
24        printf("[001] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
25
26    if (!is_null($tmp = @mysqli_savepoint($link)))
27        printf("[002] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
28
29    if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))
30        printf("[003] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
31            $host, $user, $db, $port, $socket);
32
33    $name = array();
34    if (!is_null($tmp = @mysqli_savepoint($link, $name)))
35        printf("[004] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
36
37    if (!is_null($tmp = @mysqli_savepoint($link, 'foo', $link)))
38        printf("[005] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
39
40    if (false !== ($tmp = mysqli_savepoint($link, '')))
41        printf("[006] Expecting false, got %s/%s\n", gettype($tmp), $tmp);
42
43    if (!mysqli_query($link, 'DROP TABLE IF EXISTS test'))
44        printf("[007] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
45
46    if (!mysqli_query($link, 'CREATE TABLE test(id INT) ENGINE = InnoDB'))
47        printf("[008] Cannot create test table, [%d] %s\n", mysqli_errno($link), mysqli_error($link));
48
49    if (true !== ($tmp = mysqli_autocommit($link, false)))
50        printf("[009] Cannot turn off autocommit, expecting true, got %s/%s\n", gettype($tmp), $tmp);
51
52    /* overrule autocommit */
53    if (true !== ($tmp = mysqli_savepoint($link, 'my')))
54        printf("[010] Got %s - [%d] %s\n", var_dump($tmp, true), mysqli_errno($link), mysqli_error($link));
55
56    if (!mysqli_query($link, 'INSERT INTO test(id) VALUES (1)'))
57        printf("[011] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
58
59    $tmp = mysqli_rollback($link);
60    if ($tmp !== true)
61        printf("[012] Expecting boolean/true, got %s/%s\n", gettype($tmp), $tmp);
62
63    print "done!";
64?>
65--CLEAN--
66<?php
67    require_once("clean_table.inc");
68?>
69--EXPECTF--
70Warning: mysqli_savepoint(): Savepoint name cannot be empty in %s on line %d
71done!
72