xref: /PHP-5.3/ext/mysqli/tests/bug34810.phpt (revision 0f799cc4)
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 supress '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%"field_count"]=>
81  int(0)
82  [%u|b%"host_info"]=>
83  %unicode|string%(%d) "%s"
84  [%u|b%"info"]=>
85  NULL
86  [%u|b%"insert_id"]=>
87  int(0)
88  [%u|b%"server_info"]=>
89  %unicode|string%(%d) "%s"
90  [%u|b%"server_version"]=>
91  int(%d)
92  ["stat"]=>
93  %s
94  [%u|b%"sqlstate"]=>
95  %unicode|string%(5) "00000"
96  [%u|b%"protocol_version"]=>
97  int(10)
98  [%u|b%"thread_id"]=>
99  int(%d)
100  [%u|b%"warning_count"]=>
101  int(0)
102}
103object(mysqli)#%d (%d) {
104  [%u|b%"affected_rows"]=>
105  NULL
106  [%u|b%"client_info"]=>
107  %unicode|string%(%d) "%s"
108  [%u|b%"client_version"]=>
109  int(%d)
110  [%u|b%"connect_errno"]=>
111  int(0)
112  [%u|b%"connect_error"]=>
113  NULL
114  [%u|b%"errno"]=>
115  int(0)
116  [%u|b%"error"]=>
117  %unicode|string%(0) ""
118  [%u|b%"field_count"]=>
119  NULL
120  [%u|b%"host_info"]=>
121  NULL
122  [%u|b%"info"]=>
123  NULL
124  [%u|b%"insert_id"]=>
125  NULL
126  [%u|b%"server_info"]=>
127  NULL
128  [%u|b%"server_version"]=>
129  NULL
130  ["stat"]=>
131  NULL
132  [%u|b%"sqlstate"]=>
133  NULL
134  [%u|b%"protocol_version"]=>
135  NULL
136  [%u|b%"thread_id"]=>
137  NULL
138  [%u|b%"warning_count"]=>
139  NULL
140}
141Done
142