summaryrefslogtreecommitdiff
path: root/ext/mysqli/tests/mysqli_affected_rows_oo.phpt
blob: 384ecd5e62d033752157f5b30cdbb6173bf594e9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
--TEST--
mysqli->affected_rows
--SKIPIF--
<?php
	require_once('skipif.inc');
	require_once('skipifconnectfailure.inc');
?>
--FILE--
<?php
    require_once("connect.inc");

    $mysqli = new mysqli();
    try {
        $mysqli->affected_rows;
    } catch (Error $exception) {
        echo $exception->getMessage() . "\n";
    }

    if (!$mysqli = new my_mysqli($host, $user, $passwd, $db, $port, $socket)) {
        printf("[001] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
            $host, $user, $db, $port, $socket);
    }

    if (0 !== ($tmp = $mysqli->affected_rows))
    printf("[002] Expecting int/0, got %s/%s\n", gettype($tmp), $tmp);

    if (!$mysqli->query('DROP TABLE IF EXISTS test'))
        printf("[003] [%d] %s\n", $mysqli->errno, $mysqli->error);

    if (!$mysqli->query('CREATE TABLE test(id INT, label CHAR(1), PRIMARY KEY(id)) ENGINE = ' . $engine))
        printf("[004] [%d] %s\n", $mysqli->errno, $mysqli->error);

    if (!$mysqli->query("INSERT INTO test(id, label) VALUES (1, 'a')"))
        printf("[005] [%d] %s\n",  $mysqli->errno, $mysqli->error);

    if (1 !== ($tmp = $mysqli->affected_rows))
        printf("[006] Expecting int/1, got %s/%s\n", gettype($tmp), $tmp);

    // ignore INSERT error, NOTE: command line returns 0, affected_rows returns -1 as documented
    $mysqli->query("INSERT INTO test(id, label) VALUES (1, 'a')");
    if (-1 !== ($tmp = $mysqli->affected_rows))
        printf("[007] Expecting int/-1, got %s/%s\n", gettype($tmp), $tmp);

    if (!$mysqli->query("INSERT INTO test(id, label) VALUES (1, 'a') ON DUPLICATE KEY UPDATE id = 4"))
        printf("[008] [%d] %s\n",  $mysqli->errno, $mysqli->error);

    if (2 !== ($tmp = $mysqli->affected_rows))
        printf("[009] Expecting int/2, got %s/%s\n", gettype($tmp), $tmp);

    if (!$mysqli->query("INSERT INTO test(id, label) VALUES (2, 'b'), (3, 'c')"))
        printf("[010] [%d] %s\n",  $mysqli->errno, $mysqli->error);

    if (2 !== ($tmp = $mysqli->affected_rows))
        printf("[011] Expecting int/2, got %s/%s\n", gettype($tmp), $tmp);

    if (!$mysqli->query("INSERT IGNORE INTO test(id, label) VALUES (1, 'a')")) {
        printf("[012] [%d] %s\n",  $mysqli->errno, $mysqli->error);
    }

    if (1 !== ($tmp = $mysqli->affected_rows))
        printf("[013] Expecting int/1, got %s/%s\n", gettype($tmp), $tmp);

    if (!$mysqli->query("INSERT INTO test(id, label) SELECT id + 10, label FROM test"))
        printf("[014] [%d] %s\n",  $mysqli->errno, $mysqli->error);

    if (4 !== ($tmp = $mysqli->affected_rows))
        printf("[015] Expecting int/4, got %s/%s\n", gettype($tmp), $tmp);

    if (!$mysqli->query("REPLACE INTO test(id, label) values (4, 'd')"))
        printf("[015] [%d] %s\n",  $mysqli->errno, $mysqli->error);

    if (2 !== ($tmp = $mysqli->affected_rows))
        printf("[016] Expecting int/2, got %s/%s\n", gettype($tmp), $tmp);

    if (!$mysqli->query("REPLACE INTO test(id, label) values (5, 'e')"))
        printf("[017] [%d] %s\n",  $mysqli->errno, $mysqli->error);

    if (1 !== ($tmp = $mysqli->affected_rows))
        printf("[018] Expecting int/1, got %s/%s\n", gettype($tmp), $tmp);

    if (!$mysqli->query("UPDATE test SET label = 'a' WHERE id = 2"))
        printf("[019] [%d] %s\n",  $mysqli->errno, $mysqli->error);

    if (1 !== ($tmp = $mysqli->affected_rows))
        printf("[020] Expecting int/1, got %s/%s\n", gettype($tmp), $tmp);

    if (!$mysqli->query("UPDATE test SET label = 'a' WHERE id = 2")) {
        printf("[021] [%d] %s\n",  $mysqli->errno, $mysqli->error);
    }

    if (0 !== ($tmp = $mysqli->affected_rows))
        printf("[022] Expecting int/0, got %s/%s\n", gettype($tmp), $tmp);

    if (!$mysqli->query("UPDATE test SET label = 'a' WHERE id = 100")) {
        printf("[023] [%d] %s\n",  $mysqli->errno, $mysqli->error);
    }

    if (0 !== ($tmp = $mysqli->affected_rows))
        printf("[024] Expecting int/0, got %s/%s\n", gettype($tmp), $tmp);

    if (!$mysqli->query('DROP TABLE IF EXISTS test'))
        printf("[025] [%d] %s\n", $mysqli->errno, $mysqli->error);

    $mysqli->close();

    try {
        $mysqli->affected_rows;
    } catch (Error $exception) {
        echo $exception->getMessage() . "\n";
    }

    print "done!";
?>
--CLEAN--
<?php
	require_once("clean_table.inc");
?>
--EXPECT--
Property access is not allowed yet
Property access is not allowed yet
done!