1--TEST-- 2mysqli_fetch_assoc() - 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 (!($res = mysqli_query($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 $row = mysqli_fetch_assoc($res); 36 $meta = mysqli_fetch_fields($res); 37 mysqli_free_result($res); 38 $meta = $meta[0]; 39 $length = $meta->length; 40 if ($length > strlen($insert)) { 41 42 $expected = str_repeat('0', $length - strlen($insert)); 43 $expected .= $insert; 44 if ($expected !== $row['zero']) { 45 printf("[%03d] Expecting '%s' got '%s'\n", $offset, $expected, $row['zero']); 46 return false; 47 } 48 49 } else if ($length <= 1) { 50 printf("[%03d] Length reported is too small to run test\n", $offset); 51 return false; 52 } 53 54 return true; 55 } 56 57 zerofill(2, $link, 'TINYINT'); 58 zerofill(3, $link, 'SMALLINT'); 59 zerofill(4, $link, 'MEDIUMINT'); 60 zerofill(5, $link, 'INT'); 61 zerofill(6, $link, 'INTEGER'); 62 zerofill(7, $link, 'BIGINT'); 63 zerofill(8, $link, 'FLOAT'); 64 zerofill(9, $link, 'DOUBLE'); 65 zerofill(10, $link, 'DOUBLE PRECISION'); 66 zerofill(11, $link, 'DECIMAL'); 67 zerofill(12, $link, 'DEC'); 68 69 mysqli_close($link); 70 71 print "done!"; 72?> 73--CLEAN-- 74<?php 75 require_once("clean_table.inc"); 76?> 77--EXPECTF-- 78done! 79