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 ["affected_rows"]=> 67 int(0) 68 ["client_info"]=> 69 string(%d) "%s" 70 ["client_version"]=> 71 int(%d) 72 ["connect_errno"]=> 73 int(0) 74 ["connect_error"]=> 75 NULL 76 ["errno"]=> 77 int(0) 78 ["error"]=> 79 string(0) "" 80 ["error_list"]=> 81 array(0) { 82 } 83 ["field_count"]=> 84 int(0) 85 ["host_info"]=> 86 string(%d) "%s" 87 ["info"]=> 88 NULL 89 ["insert_id"]=> 90 int(0) 91 ["server_info"]=> 92 string(%d) "%s" 93 ["server_version"]=> 94 int(%d) 95 ["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 ["sqlstate"]=> 98 string(5) "00000" 99 ["protocol_version"]=> 100 int(10) 101 ["thread_id"]=> 102 int(%d) 103 ["warning_count"]=> 104 int(0) 105} 106object(mysqli)#%d (%d) { 107 ["affected_rows"]=> 108 bool(false) 109 ["client_info"]=> 110 string(%d) "%s" 111 ["client_version"]=> 112 int(%d) 113 ["connect_errno"]=> 114 int(0) 115 ["connect_error"]=> 116 NULL 117 ["errno"]=> 118 int(0) 119 ["error"]=> 120 string(0) "" 121 ["error_list"]=> 122 bool(false) 123 ["field_count"]=> 124 bool(false) 125 ["host_info"]=> 126 bool(false) 127 ["info"]=> 128 bool(false) 129 ["insert_id"]=> 130 bool(false) 131 ["server_info"]=> 132 bool(false) 133 ["server_version"]=> 134 bool(false) 135 ["stat"]=> 136 NULL 137 ["sqlstate"]=> 138 bool(false) 139 ["protocol_version"]=> 140 bool(false) 141 ["thread_id"]=> 142 bool(false) 143 ["warning_count"]=> 144 bool(false) 145} 146Done 147