1--TEST-- 2mysqli_get_warnings() - TODO 3--SKIPIF-- 4<?php 5require_once('skipif.inc'); 6require_once('skipifemb.inc'); 7require_once('skipifconnectfailure.inc'); 8require_once('connect.inc'); 9if (!$TEST_EXPERIMENTAL) 10 die("skip - experimental (= unsupported) feature"); 11?> 12--FILE-- 13<?php 14 require_once("connect.inc"); 15 16 $tmp = NULL; 17 $link = NULL; 18 19 if (!is_null($tmp = @mysqli_get_warnings())) 20 printf("[001] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); 21 22 if (!is_null($tmp = @mysqli_get_warnings($link))) 23 printf("[002] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); 24 25 if (!is_null($tmp = @mysqli_get_warnings(''))) 26 printf("[002] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp); 27 28 if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)) { 29 printf("[003] [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error()); 30 } 31 32 if (false !== ($tmp = mysqli_get_warnings($link))) { 33 printf("[004] Expecting boolean/false, got %s/%s\n", gettype($tmp), (is_object($tmp) ? var_dump($tmp, true) : $tmp)); 34 } 35 36 if (!mysqli_query($link, "DROP TABLE IF EXISTS test")) 37 printf("[005] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 38 39 if (!mysqli_query($link, "CREATE TABLE test (id SMALLINT)")) 40 printf("[006] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 41 42 if (!mysqli_query($link, "INSERT INTO test (id) VALUES (1000000)")) 43 printf("[007] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 44 45 if (!is_object($warning = mysqli_get_warnings($link)) || 'mysqli_warning' != get_class($warning)) { 46 printf("[008] Expecting object/mysqli_warning, got %s/%s\n", gettype($tmp), (is_object($tmp) ? var_dump($tmp, true) : $tmp)); 47 } 48 49 if (!method_exists($warning, 'next')) 50 printf("[009] Borked object, method next is missing\n"); 51 52 $properties = array_merge(get_object_vars($warning), get_class_vars(get_class($warning))); 53 if (!empty($properties)) 54 printf("[010] Properties have always been magic, hidden things - why are they visible now, a BC break...\n"); 55 56 if ((!is_string($warning->message)) || ('' == $warning->message)) /* NULL or not there at all */ 57 printf("[011] Expecting string/not empty, got %s/%s\n", gettype($warning->message), $warning->message); 58 59 if ((!is_string($warning->sqlstate)) || ('' == $warning->sqlstate)) /* NULL or not there at all */ 60 printf("[012] Expecting string/not empty, got %s/%s\n", gettype($warning->sqlstate), $warning->sqlstate); 61 62 if ((!is_int($warning->errno)) || (0 == $warning->errno)) /* NULL or not there at all */ 63 printf("[013] Expecting int/not 0, got %s/%s\n", gettype($warning->errno), $warning->errno); 64 65 if (false !== ($tmp = $warning->next())) 66 printf("[014] Expecting boolean/true, got %s/%s\n", gettype($tmp), $tmp); 67 68 if (!mysqli_query($link, "INSERT INTO test (id) VALUES (1000000), (1000001)")) 69 printf("[015] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 70 71 if (($tmp = mysqli_warning_count($link)) !== 2) 72 printf("[016] Expecting 2 warnings, got %d warnings", $tmp); 73 74 if (!is_object($warning = mysqli_get_warnings($link)) || 'mysqli_warning' != get_class($warning)) { 75 printf("[017] Expecting object/mysqli_warning, got %s/%s\n", gettype($tmp), (is_object($tmp) ? var_dump($tmp, true) : $tmp)); 76 } 77 78 if (true !== ($tmp = $warning->next())) 79 printf("[018] Expecting boolean/true, got %s/%s\n", gettype($tmp), $tmp); 80 81 if (false !== ($tmp = $warning->next())) 82 printf("[020] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp); 83 84 mysqli_close($link); 85 86 87 if (!$mysqli = new my_mysqli($host, $user, $passwd, $db, $port, $socket)) 88 printf("[021] Cannot create mysqli object: [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error()); 89 90 if (!$mysqli->query("DROP TABLE IF EXISTS t1")) 91 printf("[022] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 92 93 if (!$mysqli->query("CREATE TABLE t1 (a smallint)")) 94 printf("[023] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 95 96 if (!is_object($warning = new mysqli_warning($mysqli))) 97 printf("[024] Expecting object/mysqli_warning, got %s/%s", gettype($warning), $warning); 98 99 if (!is_string($warning->message) || ('' == $warning->message)) 100 printf("[025] Expecting string, got %s/%s", gettype($warning->message), $warning->message); 101 102 if (!$mysqli->query("DROP TABLE t1")) 103 printf("[026] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 104 105 /* Yes, I really want to check if the object property is empty */ 106 if (!$mysqli = new my_mysqli($host, $user, $passwd, $db, $port, $socket)) 107 printf("[027] Cannot create mysqli object: [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error()); 108 109 $warning = new mysqli_warning($mysqli); 110 if (false !== ($tmp = $warning->next())) 111 printf("[028] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp); 112 113 if ('' != ($tmp = $warning->message)) 114 printf("[029] Expecting string/empty, got %s/%s\n", gettype($tmp), $tmp); 115 116 if (!$mysqli = new my_mysqli($host, $user, $passwd, $db, $port, $socket)) 117 printf("[030] Cannot create mysqli object: [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error()); 118 119 if (!$mysqli->query("DROP TABLE IF EXISTS t1")) 120 printf("[031] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 121 122 if (!$mysqli->query("CREATE TABLE t1 (a smallint)")) 123 printf("[032] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 124 125 /* out of range, three warnings */ 126 if (!$mysqli->query("INSERT IGNORE INTO t1(a) VALUES (65536), (65536), (65536)")) 127 printf("[033] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 128 129 $warning = new mysqli_warning($mysqli); 130 $i = 1; 131 while ($warning->next() && ('' != ($tmp = $warning->message))) { 132 $i++; 133 } 134 if (3 != $i) 135 printf("[034] Expecting three warnings, got %d warnings\n", $i); 136 137 $stmt = mysqli_stmt_init(); 138 $warning = new mysqli_warning($stmt); 139 if (false !== ($tmp = $warning->next())) 140 printf("[035] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp); 141 142 print "done!"; 143?> 144<?php 145require_once("connect.inc"); 146if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)) 147 printf("[c001] [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error()); 148 149if (!mysqli_query($link, "DROP TABLE IF EXISTS test")) 150 printf("[c002] Cannot drop table, [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 151 152if (!mysqli_query($link, "DROP TABLE IF EXISTS t1")) 153 printf("[c003] Cannot drop table, [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 154 155mysqli_close($link); 156?> 157--EXPECTF-- 158done! 159