1--TEST-- 2mysqli_stmt_bind_result() - ZEROFILL 3--SKIPIF-- 4<?php 5require_once('skipif.inc'); 6require_once('skipifemb.inc'); 7require_once('skipifconnectfailure.inc'); 8?> 9--FILE-- 10<?php 11 require_once('connect.inc'); 12 require_once('table.inc'); 13 14 function zerofill($offset, $link, $datatype, $insert = 1) { 15 16 mysqli_query($link, 'ALTER TABLE test DROP zero'); 17 $sql = sprintf('ALTER TABLE test ADD zero %s UNSIGNED ZEROFILL', $datatype); 18 if (!mysqli_query($link, $sql)) { 19 // no worries - server might not support it 20 return true; 21 } 22 23 if (!mysqli_query($link, sprintf('UPDATE test SET zero = %s', $insert))) { 24 printf("[%03d] UPDATE failed, [%d] %s\n", 25 $offset, mysqli_errno($link), mysqli_error($link)); 26 return false; 27 } 28 29 if (!($stmt = mysqli_prepare($link, 'SELECT zero FROM test LIMIT 1'))) { 30 printf("[%03d] SELECT failed, [%d] %s\n", 31 $offset, mysqli_errno($link), mysqli_error($link)); 32 return false; 33 } 34 35 $result = null; 36 if (!mysqli_stmt_bind_result($stmt, $result)) { 37 printf("[%03d] Bind failed, [%d] %s\n", 38 mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 39 return false; 40 } 41 42 if (!mysqli_stmt_execute($stmt) || !mysqli_stmt_fetch($stmt)) { 43 printf("[%03d] Execute or fetch failed, [%d] %s\n", 44 mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt)); 45 return false; 46 } 47 48 $res = mysqli_stmt_result_metadata($stmt); 49 $meta = mysqli_fetch_fields($res); 50 mysqli_stmt_free_result($stmt); 51 52 $meta = $meta[0]; 53 $length = $meta->length; 54 if ($length > strlen($insert)) { 55 56 $expected = str_repeat('0', $length - strlen($insert)); 57 $expected .= $insert; 58 if ($expected !== $result) { 59 printf("[%03d] Expecting '%s' got '%s'\n", $offset, $expected, $result); 60 return false; 61 } 62 63 } else if ($length <= 1) { 64 printf("[%03d] Length reported is too small to run test\n", $offset); 65 return false; 66 } 67 68 69 return true; 70 } 71 72 /* 73 We map those to PHP numeric types - 74 no padding/filling done. Neither with libmysql nor with mysqlnd. 75 zerofill(2, $link, 'TINYINT'); 76 zerofill(3, $link, 'SMALLINT'); 77 zerofill(4, $link, 'MEDIUMINT'); 78 zerofill(5, $link, 'INT'); 79 zerofill(6, $link, 'INTEGER'); 80 zerofill(7, $link, 'BIGINT'); 81 zerofill(8, $link, 'FLOAT'); 82 zerofill(9, $link, 'DOUBLE'); 83 zerofill(10, $link, 'DOUBLE PRECISION'); 84 */ 85 zerofill(11, $link, 'DECIMAL'); 86 zerofill(12, $link, 'DEC'); 87 88 mysqli_close($link); 89 90 print "done!"; 91?> 92--CLEAN-- 93<?php 94 require_once("clean_table.inc"); 95?> 96--EXPECTF-- 97done!