xref: /PHP-5.4/ext/mysqli/tests/bug34810.phpt (revision ac40c0b5)
1--TEST--
2Bug #34810 (mysqli::init() and others use wrong $this pointer without checks)
3--SKIPIF--
4<?php
5require_once('skipif.inc');
6require_once('skipifconnectfailure.inc');
7?>
8--FILE--
9<?php
10
11class DbConnection {
12	public function connect() {
13		require_once("connect.inc");
14
15		$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket);
16		var_dump($link);
17
18		$link = mysqli_init();
19		/* @ is to suppress 'Property access is not allowed yet' */
20		@var_dump($link);
21
22		$mysql = new my_mysqli($host, $user, $passwd, $db, $port, $socket);
23		$mysql->query("DROP TABLE IF EXISTS test_warnings");
24		$mysql->query("CREATE TABLE test_warnings (a int not null)");
25		$mysql->query("SET sql_mode=''");
26		$mysql->query("INSERT INTO test_warnings VALUES (1),(2),(NULL)");
27
28		$warning = $mysql->get_warnings();
29		if (!$warning)
30			printf("[001] No warning!\n");
31
32		if ($warning->errno == 1048 || $warning->errno == 1253) {
33			/* 1048 - Column 'a' cannot be null, 1263 - Data truncated; NULL supplied to NOT NULL column 'a' at row */
34			if ("HY000" != $warning->sqlstate)
35				printf("[003] Wrong sql state code: %s\n", $warning->sqlstate);
36
37			if ("" == $warning->message)
38				printf("[004] Message string must not be empty\n");
39
40
41		} else {
42			printf("[002] Empty error message!\n");
43			var_dump($warning);
44		}
45	}
46}
47
48$db = new DbConnection();
49$db->connect();
50
51echo "Done\n";
52?>
53--CLEAN--
54<?php
55require_once("connect.inc");
56if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))
57   printf("[c001] [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
58
59if (!mysqli_query($link, "DROP TABLE IF EXISTS test_warnings"))
60	printf("[c002] Cannot drop table, [%d] %s\n", mysqli_errno($link), mysqli_error($link));
61
62mysqli_close($link);
63?>
64--EXPECTF--
65object(mysqli)#%d (%d) {
66  [%u|b%"affected_rows"]=>
67  int(0)
68  [%u|b%"client_info"]=>
69  %unicode|string%(%d) "%s"
70  [%u|b%"client_version"]=>
71  int(%d)
72  [%u|b%"connect_errno"]=>
73  int(0)
74  [%u|b%"connect_error"]=>
75  NULL
76  [%u|b%"errno"]=>
77  int(0)
78  [%u|b%"error"]=>
79  %unicode|string%(0) ""
80  [%u|b%"error_list"]=>
81  array(0) {
82  }
83  [%u|b%"field_count"]=>
84  int(0)
85  [%u|b%"host_info"]=>
86  %unicode|string%(%d) "%s"
87  [%u|b%"info"]=>
88  NULL
89  [%u|b%"insert_id"]=>
90  int(0)
91  [%u|b%"server_info"]=>
92  %unicode|string%(%d) "%s"
93  [%u|b%"server_version"]=>
94  int(%d)
95  [%u|b%"stat"]=>
96  string(%d) "Uptime: %d  Threads: %d  Questions: %d  Slow queries: %d  Opens: %d  Flush tables: %d  Open tables: %d  Queries per second avg: %d.%d"
97  [%u|b%"sqlstate"]=>
98  %unicode|string%(5) "00000"
99  [%u|b%"protocol_version"]=>
100  int(10)
101  [%u|b%"thread_id"]=>
102  int(%d)
103  [%u|b%"warning_count"]=>
104  int(0)
105}
106object(mysqli)#%d (%d) {
107  [%u|b%"affected_rows"]=>
108  NULL
109  [%u|b%"client_info"]=>
110  %unicode|string%(%d) "%s"
111  [%u|b%"client_version"]=>
112  int(%d)
113  [%u|b%"connect_errno"]=>
114  int(0)
115  [%u|b%"connect_error"]=>
116  NULL
117  [%u|b%"errno"]=>
118  int(0)
119  [%u|b%"error"]=>
120  %unicode|string%(0) ""
121  [%u|b%"error_list"]=>
122  NULL
123  [%u|b%"field_count"]=>
124  NULL
125  [%u|b%"host_info"]=>
126  NULL
127  [%u|b%"info"]=>
128  NULL
129  [%u|b%"insert_id"]=>
130  NULL
131  [%u|b%"server_info"]=>
132  NULL
133  [%u|b%"server_version"]=>
134  NULL
135  [%u|b%"stat"]=>
136  NULL
137  [%u|b%"sqlstate"]=>
138  NULL
139  [%u|b%"protocol_version"]=>
140  NULL
141  [%u|b%"thread_id"]=>
142  NULL
143  [%u|b%"warning_count"]=>
144  NULL
145}
146Done
147