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