1--TEST--
2mysqli->affected_rows
3--SKIPIF--
4<?php
5    require_once('skipif.inc');
6    require_once('skipifconnectfailure.inc');
7?>
8--FILE--
9<?php
10    require_once("connect.inc");
11
12    $mysqli = new mysqli();
13    try {
14        $mysqli->affected_rows;
15    } catch (Error $exception) {
16        echo $exception->getMessage() . "\n";
17    }
18
19    if (!$mysqli = new my_mysqli($host, $user, $passwd, $db, $port, $socket)) {
20        printf("[001] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
21            $host, $user, $db, $port, $socket);
22    }
23
24    if (0 !== ($tmp = $mysqli->affected_rows))
25    printf("[002] Expecting int/0, got %s/%s\n", gettype($tmp), $tmp);
26
27    if (!$mysqli->query('DROP TABLE IF EXISTS test'))
28        printf("[003] [%d] %s\n", $mysqli->errno, $mysqli->error);
29
30    if (!$mysqli->query('CREATE TABLE test(id INT, label CHAR(1), PRIMARY KEY(id)) ENGINE = ' . $engine))
31        printf("[004] [%d] %s\n", $mysqli->errno, $mysqli->error);
32
33    if (!$mysqli->query("INSERT INTO test(id, label) VALUES (1, 'a')"))
34        printf("[005] [%d] %s\n",  $mysqli->errno, $mysqli->error);
35
36    if (1 !== ($tmp = $mysqli->affected_rows))
37        printf("[006] Expecting int/1, got %s/%s\n", gettype($tmp), $tmp);
38
39    // ignore INSERT error, NOTE: command line returns 0, affected_rows returns -1 as documented
40    $mysqli->query("INSERT INTO test(id, label) VALUES (1, 'a')");
41    if (-1 !== ($tmp = $mysqli->affected_rows))
42        printf("[007] Expecting int/-1, got %s/%s\n", gettype($tmp), $tmp);
43
44    if (!$mysqli->query("INSERT INTO test(id, label) VALUES (1, 'a') ON DUPLICATE KEY UPDATE id = 4"))
45        printf("[008] [%d] %s\n",  $mysqli->errno, $mysqli->error);
46
47    if (2 !== ($tmp = $mysqli->affected_rows))
48        printf("[009] Expecting int/2, got %s/%s\n", gettype($tmp), $tmp);
49
50    if (!$mysqli->query("INSERT INTO test(id, label) VALUES (2, 'b'), (3, 'c')"))
51        printf("[010] [%d] %s\n",  $mysqli->errno, $mysqli->error);
52
53    if (2 !== ($tmp = $mysqli->affected_rows))
54        printf("[011] Expecting int/2, got %s/%s\n", gettype($tmp), $tmp);
55
56    if (!$mysqli->query("INSERT IGNORE INTO test(id, label) VALUES (1, 'a')")) {
57        printf("[012] [%d] %s\n",  $mysqli->errno, $mysqli->error);
58    }
59
60    if (1 !== ($tmp = $mysqli->affected_rows))
61        printf("[013] Expecting int/1, got %s/%s\n", gettype($tmp), $tmp);
62
63    if (!$mysqli->query("INSERT INTO test(id, label) SELECT id + 10, label FROM test"))
64        printf("[014] [%d] %s\n",  $mysqli->errno, $mysqli->error);
65
66    if (4 !== ($tmp = $mysqli->affected_rows))
67        printf("[015] Expecting int/4, got %s/%s\n", gettype($tmp), $tmp);
68
69    if (!$mysqli->query("REPLACE INTO test(id, label) values (4, 'd')"))
70        printf("[015] [%d] %s\n",  $mysqli->errno, $mysqli->error);
71
72    if (2 !== ($tmp = $mysqli->affected_rows))
73        printf("[016] Expecting int/2, got %s/%s\n", gettype($tmp), $tmp);
74
75    if (!$mysqli->query("REPLACE INTO test(id, label) values (5, 'e')"))
76        printf("[017] [%d] %s\n",  $mysqli->errno, $mysqli->error);
77
78    if (1 !== ($tmp = $mysqli->affected_rows))
79        printf("[018] Expecting int/1, got %s/%s\n", gettype($tmp), $tmp);
80
81    if (!$mysqli->query("UPDATE test SET label = 'a' WHERE id = 2"))
82        printf("[019] [%d] %s\n",  $mysqli->errno, $mysqli->error);
83
84    if (1 !== ($tmp = $mysqli->affected_rows))
85        printf("[020] Expecting int/1, got %s/%s\n", gettype($tmp), $tmp);
86
87    if (!$mysqli->query("UPDATE test SET label = 'a' WHERE id = 2")) {
88        printf("[021] [%d] %s\n",  $mysqli->errno, $mysqli->error);
89    }
90
91    if (0 !== ($tmp = $mysqli->affected_rows))
92        printf("[022] Expecting int/0, got %s/%s\n", gettype($tmp), $tmp);
93
94    if (!$mysqli->query("UPDATE test SET label = 'a' WHERE id = 100")) {
95        printf("[023] [%d] %s\n",  $mysqli->errno, $mysqli->error);
96    }
97
98    if (0 !== ($tmp = $mysqli->affected_rows))
99        printf("[024] Expecting int/0, got %s/%s\n", gettype($tmp), $tmp);
100
101    if (!$mysqli->query('DROP TABLE IF EXISTS test'))
102        printf("[025] [%d] %s\n", $mysqli->errno, $mysqli->error);
103
104    $mysqli->close();
105
106    try {
107        $mysqli->affected_rows;
108    } catch (Error $exception) {
109        echo $exception->getMessage() . "\n";
110    }
111
112    print "done!";
113?>
114--CLEAN--
115<?php
116    require_once("clean_table.inc");
117?>
118--EXPECT--
119Property access is not allowed yet
120Property access is not allowed yet
121done!
122