forked from php/php-src
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmysql_affected_rows.phpt
125 lines (91 loc) · 4.58 KB
/
mysql_affected_rows.phpt
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
122
123
124
125
--TEST--
mysql_affected_rows()
--SKIPIF--
<?php
require_once('skipif.inc');
require_once('skipifconnectfailure.inc');
?>
--FILE--
<?php
include_once("connect.inc");
include_once('setupdefault.inc');
$tmp = NULL;
$link = NULL;
if (0 !== ($tmp = @mysql_affected_rows()))
printf("[001] Expecting int/0, got %s/%s\n", gettype($tmp), $tmp);
if (null !== ($tmp = @mysql_affected_rows($link)))
printf("[002] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
if (!is_null($tmp = @mysql_affected_rows($link, $link)))
printf("[003] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
if (!$link = my_mysql_connect($host, $user, $passwd, $db, $port, $socket))
printf("[004] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
$host, $user, $db, $port, $socket);
if (-1 !== ($tmp = mysql_affected_rows($link)))
printf("[005] Expecting int/-1, got %s/%s. [%d] %s\n",
gettype($tmp), $tmp, mysql_errno($link), mysql_error($link));
if (!mysql_query('DROP TABLE IF EXISTS test', $link))
printf("[006] [%d] %s\n", mysql_errno($link), mysql_error($link));
if (!mysql_query('CREATE TABLE test(id INT, label CHAR(1), PRIMARY KEY(id)) ENGINE = ' . $engine, $link))
printf("[007] [%d] %s\n", mysql_errno($link), mysql_error($link));
if (!mysql_query("INSERT INTO test(id, label) VALUES (1, 'a')", $link))
printf("[008] [%d] %s\n", mysql_errno($link), mysql_error($link));
if (1 !== ($tmp = mysql_affected_rows($link)))
printf("[010] Expecting int/1, got %s/%s\n", gettype($tmp), $tmp);
// ignore INSERT error, NOTE: command line returns 0, affected_rows returns -1 as documented
@mysql_query("INSERT INTO test(id, label) VALUES (1, 'a')", $link);
if (-1 !== ($tmp = mysql_affected_rows($link)))
printf("[011] Expecting int/-1, got %s/%s\n", gettype($tmp), $tmp);
if (!mysql_query("INSERT INTO test(id, label) VALUES (1, 'a') ON DUPLICATE KEY UPDATE id = 4", $link))
printf("[012] [%d] %s\n", mysql_errno($link), mysql_error($link));
if (2 !== ($tmp = mysql_affected_rows($link)))
printf("[013] Expecting int/2, got %s/%s\n", gettype($tmp), $tmp);
if (!mysql_query("INSERT INTO test(id, label) VALUES (2, 'b'), (3, 'c')", $link))
printf("[014] [%d] %s\n", mysql_errno($link), mysql_error($link));
if (2 !== ($tmp = mysql_affected_rows($link)))
printf("[015] Expecting int/2, got %s/%s\n", gettype($tmp), $tmp);
if (!mysql_query("INSERT IGNORE INTO test(id, label) VALUES (1, 'a')", $link)) {
printf("[016] [%d] %s\n", mysql_errno($link), mysql_error($link));
}
if (1 !== ($tmp = mysql_affected_rows($link)))
printf("[017] Expecting int/1, got %s/%s\n", gettype($tmp), $tmp);
if (!mysql_query("INSERT INTO test(id, label) SELECT id + 10, label FROM test", $link))
printf("[018] [%d] %s\n", mysql_errno($link), mysql_error($link));
if (4 !== ($tmp = mysql_affected_rows($link)))
printf("[019] Expecting int/4, got %s/%s\n", gettype($tmp), $tmp);
if (!mysql_query("REPLACE INTO test(id, label) values (4, 'd')", $link))
printf("[020] [%d] %s\n", mysql_errno($link), mysql_error($link));
if (2 !== ($tmp = mysql_affected_rows($link)))
printf("[021] Expecting int/2, got %s/%s\n", gettype($tmp), $tmp);
if (!mysql_query("REPLACE INTO test(id, label) values (5, 'e')", $link))
printf("[022] [%d] %s\n", mysql_errno($link), mysql_error($link));
if (1 !== ($tmp = mysql_affected_rows($link)))
printf("[023] Expecting int/1, got %s/%s\n", gettype($tmp), $tmp);
if (!mysql_query("UPDATE test SET label = 'a' WHERE id = 2", $link))
printf("[024] [%d] %s\n", mysql_errno($link), mysql_error($link));
if (1 !== ($tmp = mysql_affected_rows($link)))
printf("[025] Expecting int/1, got %s/%s\n", gettype($tmp), $tmp);
if (!mysql_query("UPDATE test SET label = 'a' WHERE id = 2", $link)) {
printf("[025] [%d] %s\n", mysql_errno($link), mysql_error($link));
}
if (0 !== ($tmp = mysql_affected_rows($link)))
printf("[026] Expecting int/0, got %s/%s\n", gettype($tmp), $tmp);
if (!mysql_query("UPDATE test SET label = 'a' WHERE id = 100", $link)) {
printf("[025] [%d] %s\n", mysql_errno($link), mysql_error($link));
}
if (0 !== ($tmp = mysql_affected_rows($link)))
printf("[026] Expecting int/0, got %s/%s\n", gettype($tmp), $tmp);
if (0 !== ($tmp = mysql_affected_rows()))
printf("[027] Expecting int/0, got %s/%s\n", gettype($tmp), $tmp);
if (!mysql_query('DROP TABLE IF EXISTS test', $link))
printf("[028] [%d] %s\n", mysql_errno($link), mysql_error($link));
mysql_close($link);
if (false !== ($tmp = @mysql_affected_rows($link)))
printf("[029] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
print "done!";
?>
--CLEAN--
<?php
require_once("clean_table.inc");
?>
--EXPECTF--
done!