1--TEST-- 2Bug #45019 (Segmentation fault with SELECT ? and UNION) 3--SKIPIF-- 4<?php 5require_once('skipif.inc'); 6require_once('skipifconnectfailure.inc'); 7?> 8--FILE-- 9<?php 10 require_once("connect.inc"); 11 require_once("table.inc"); 12 13 // Regular (non-prepared) queries 14 print "Using CAST('somestring' AS CHAR)...\n"; 15 if (!($res = $link->query("SELECT CAST('one' AS CHAR) AS column1 UNION SELECT CAST('three' AS CHAR) UNION SELECT CAST('two' AS CHAR)"))) 16 printf("[001] [%d] %s\n", $link->errno, $link->error); 17 18 $data = array(); 19 while ($row = $res->fetch_assoc()) { 20 $data[] = $row['column1']; 21 var_dump($row['column1']); 22 } 23 $res->free(); 24 25 // Prepared Statements 26 if (!($stmt = $link->prepare("SELECT CAST('one' AS CHAR) AS column1 UNION SELECT CAST('three' AS CHAR) UNION SELECT CAST('two' AS CHAR)"))) 27 printf("[002] [%d] %s\n", $link->errno, $link->error); 28 29 $column1 = null; 30 if (!$stmt->bind_result($column1) || !$stmt->execute()) 31 printf("[003] [%d] %s\n", $stmt->errno, $stmt->error); 32 33 $index = 0; 34 while ($stmt->fetch()) { 35 /* NOTE: libmysql - http://bugs.mysql.com/bug.php?id=47483 */ 36 if ($data[$index] != $column1) { 37 if ($IS_MYSQLND || $index != 1) { 38 printf("[004] Row %d, expecting %s/%s got %s/%s\n", 39 $index + 1, gettype($data[$index]), $data[$index], gettype($column1), $column1); 40 } else { 41 if ($column1 != "thre") 42 printf("[005] Got '%s'. Please check if http://bugs.mysql.com/bug.php?id=47483 has been fixed and adapt tests bug45019.phpt/mysqli_ps_select_union.phpt", $column1); 43 } 44 } 45 $index++; 46 } 47 $stmt->close(); 48 49 $link->close(); 50 51 print "done!"; 52?> 53--EXPECT-- 54Using CAST('somestring' AS CHAR)... 55string(3) "one" 56string(5) "three" 57string(3) "two" 58done! 59