1--TEST-- 2MySQL Bug #49406 (Binding params doesn't work when selecting a date inside a CASE-WHEN, http://bugs.mysql.com/bug.php?id=49406) 3--EXTENSIONS-- 4mysqli 5--SKIPIF-- 6<?php 7require_once 'skipifconnectfailure.inc'; 8?> 9--FILE-- 10<?php 11 require_once 'connect.inc'; 12 13 if (!($link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))) 14 printf("[001] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n", 15 $host, $user, $db, $port, $socket); 16 17 $query = "SELECT CASE WHEN 0 THEN CAST('2009-12-03' AS DATE) ELSE CAST('2009-12-03' AS DATE) END"; 18 19 if (!$res = $link->query($query)) 20 printf("[002] [%d] %s\n", $link->errno, $link->error); 21 22 if (!$row = $res->fetch_row()) 23 printf("[003] No result, [%d] %s\n", $link->errno, $link->error); 24 25 $res->free(); 26 27 if ($row[0] != '2009-12-03') { 28 printf("[004] Expecting '2009-12-03' got '%s'\n", $row[0]); 29 } 30 31 if (!$stmt = $link->prepare($query)) 32 printf("[005] [%d] %s\n", $link->errno, $link->error); 33 34 if (!$stmt->execute() || !$stmt->store_result()) 35 printf("[006] [%d] %s\n", $stmt->errno, $stmt->error); 36 37 38 $datatypes = array( 39 MYSQLI_TYPE_TINY => "TINY", 40 MYSQLI_TYPE_SHORT => "SHORT", 41 MYSQLI_TYPE_LONG => "LONG", 42 MYSQLI_TYPE_FLOAT => "FLOAT", 43 MYSQLI_TYPE_DOUBLE => "DOUBLE", 44 MYSQLI_TYPE_TIMESTAMP => "TIMESTAMP", 45 MYSQLI_TYPE_LONGLONG => "LONGLONG", 46 MYSQLI_TYPE_INT24 => "INT24", 47 MYSQLI_TYPE_DATE => "DATE", 48 MYSQLI_TYPE_TIME => "TIME", 49 MYSQLI_TYPE_DATETIME => "DATETIME", 50 MYSQLI_TYPE_YEAR => "YEAR", 51 MYSQLI_TYPE_ENUM => "ENUM", 52 MYSQLI_TYPE_SET => "SET", 53 MYSQLI_TYPE_TINY_BLOB => "TINYBLOB", 54 MYSQLI_TYPE_MEDIUM_BLOB => "MEDIUMBLOB", 55 MYSQLI_TYPE_LONG_BLOB => "LONGBLOB", 56 MYSQLI_TYPE_BLOB => "BLOB", 57 MYSQLI_TYPE_VAR_STRING => "VAR_STRING", 58 MYSQLI_TYPE_STRING => "STRING", 59 MYSQLI_TYPE_NULL => "NULL", 60 MYSQLI_TYPE_NEWDATE => "NEWDATE", 61 MYSQLI_TYPE_GEOMETRY => "GEOMETRY", 62 ); 63 64 $meta_res = $stmt->result_metadata(); 65 for ($field_idx = 0; $field_idx < $meta_res->field_count; $field_idx++) { 66 $field = $meta_res->fetch_field(); 67 printf("Field : %d\n", $field_idx); 68 printf("Name : %s\n", $field->name); 69 printf("Orgname : %s\n", $field->orgname); 70 printf("Table : %s\n", $field->table); 71 printf("Orgtable : %s\n", $field->orgtable); 72 printf("Maxlength : %d\n", $field->max_length); 73 printf("Length : %d\n", $field->length); 74 printf("Charsetnr : %d\n", $field->charsetnr); 75 printf("Flags : %d\n", $field->flags); 76 printf("Type : %d (%s)\n", $field->type, (isset($datatypes[$field->type])) ? $datatypes[$field->type] : 'unknown'); 77 printf("Decimals : %d\n", $field->decimals); 78 } 79 80 $row_stmt = null; 81 if (!$stmt->bind_result($row_stmt) || !$stmt->fetch()) 82 printf("[007] [%d] %s\n", $stmt->errno, $stmt->error); 83 84 if ($row[0] != $row_stmt) { 85 printf("[008] PS and non-PS results differ, dumping data\n"); 86 var_dump($row[0]); 87 var_dump($row_stmt); 88 } 89 90 $stmt->close(); 91 $link->close(); 92 93 echo "done"; 94?> 95--EXPECTF-- 96Field : %s 97Name : %s 98Orgname :%s 99Table :%s 100Orgtable :%s 101Maxlength : %d 102Length : %d 103Charsetnr : %d 104Flags : %d 105Type : %d (%s) 106Decimals : %d 107done 108