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 var_dump($link); 20 21 $mysql = new my_mysqli($host, $user, $passwd, $db, $port, $socket); 22 $mysql->query("DROP TABLE IF EXISTS test_warnings"); 23 $mysql->query("CREATE TABLE test_warnings (a int not null)"); 24 $mysql->query("SET sql_mode=''"); 25 $mysql->query("INSERT INTO test_warnings VALUES (1),(2),(NULL)"); 26 27 $warning = $mysql->get_warnings(); 28 if (!$warning) 29 printf("[001] No warning!\n"); 30 31 if ($warning->errno == 1048 || $warning->errno == 1253) { 32 /* 1048 - Column 'a' cannot be null, 1263 - Data truncated; NULL supplied to NOT NULL column 'a' at row */ 33 if ("HY000" != $warning->sqlstate) 34 printf("[003] Wrong sql state code: %s\n", $warning->sqlstate); 35 36 if ("" == $warning->message) 37 printf("[004] Message string must not be empty\n"); 38 } else { 39 printf("[002] Empty error message!\n"); 40 var_dump($warning); 41 } 42 } 43} 44 45$db = new DbConnection(); 46$db->connect(); 47 48echo "Done\n"; 49?> 50--CLEAN-- 51<?php 52require_once("connect.inc"); 53if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)) 54 printf("[c001] [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error()); 55 56if (!mysqli_query($link, "DROP TABLE IF EXISTS test_warnings")) 57 printf("[c002] Cannot drop table, [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 58 59mysqli_close($link); 60?> 61--EXPECTF-- 62object(mysqli)#%d (%d) { 63 ["affected_rows"]=> 64 int(0) 65 ["client_info"]=> 66 string(%d) "%s" 67 ["client_version"]=> 68 int(%d) 69 ["connect_errno"]=> 70 int(0) 71 ["connect_error"]=> 72 NULL 73 ["errno"]=> 74 int(0) 75 ["error"]=> 76 string(0) "" 77 ["error_list"]=> 78 array(0) { 79 } 80 ["field_count"]=> 81 int(0) 82 ["host_info"]=> 83 string(%d) "%s" 84 ["info"]=> 85 NULL 86 ["insert_id"]=> 87 int(0) 88 ["server_info"]=> 89 string(%d) "%s" 90 ["server_version"]=> 91 int(%d) 92 ["sqlstate"]=> 93 string(5) "00000" 94 ["protocol_version"]=> 95 int(10) 96 ["thread_id"]=> 97 int(%d) 98 ["warning_count"]=> 99 int(0) 100} 101object(mysqli)#%d (%d) { 102 ["client_info"]=> 103 string(%d) "%s" 104 ["client_version"]=> 105 int(%d) 106 ["connect_errno"]=> 107 int(0) 108 ["connect_error"]=> 109 NULL 110 ["errno"]=> 111 int(0) 112 ["error"]=> 113 string(0) "" 114} 115Done 116