1--TEST-- 2mysqli_fetch_array() 3--SKIPIF-- 4<?php 5require_once('skipif.inc'); 6require_once('skipifconnectfailure.inc'); 7?> 8--FILE-- 9<?php 10 require("table.inc"); 11 12 // do as much as we can do in 5 seconds 13 $start = microtime(true); 14 for ($id = 100, $start = microtime(true); (microtime(true) - $start) < 5; $id++) { 15 if (!mysqli_query($link, $sql = sprintf("INSERT INTO test(id, label) VALUES (%d, '%s')", 16 $id, mysqli_real_escape_string($link, chr(65 + ($id % 26)))))) { 17 printf("[001] %s failed: [%d] %s\n", $sql, mysqli_errno($link), mysqli_error($link)); 18 break; 19 } 20 } 21 22 if (!$res = mysqli_query($link, 'SELECT id, label FROM test')) { 23 printf("[002] SELECT failed: [%d] %s\n", mysqli_errno($link), mysqli_errno($link)); 24 } 25 26 while ($row = mysqli_fetch_array($res)) { 27 // overwrite results and check if the cache magic works 28 $row['label'] = NULL; 29 } 30 mysqli_free_result($res); 31 32 if (!$res = mysqli_query($link, 'SELECT id, label FROM test')) { 33 printf("[003] SELECT failed: [%d] %s\n", mysqli_errno($link), mysqli_errno($link)); 34 } 35 36 $i = 0; 37 $results = array(); 38 while ($row = mysqli_fetch_array($res, MYSQLI_BOTH)) { 39 40 // create copies and destroy later 41 $results[$i++] = &$row; 42 if ($i % 999) { 43 $results = array(); 44 } 45 46 if ($row[0] < 0 || $row[0] > $id) { 47 printf("[004] Unexpected result row[0] = '%s' (range 0...%d), [%d] %s\n", 48 $row[0], $id, mysqli_errno($link), mysqli_error($link)); 49 break; 50 } 51 if ($row[0] !== $row['id']) { 52 printf("[005] Unexpected result row[0] = '%s', row[id] = '%s', [%d] %s\n", 53 $row[0], $row[id], mysqli_errno($link), mysqli_error($link)); 54 break; 55 } 56 57 $len = strlen($row[1]); 58 if (!is_string($row[1]) || $len == 0 || $len > 1) { 59 printf("[006] Unexpected result row[1] = '%s', [%d] %s\n", 60 $row[1], mysqli_errno($link), mysqli_error($link)); 61 break; 62 } 63 if ($row[1] !== $row['label']) { 64 printf("[007] Unexpected result row[1] = '%s', row[label] = '%s', [%d] %s\n", 65 $row[1], $row['label'], mysqli_errno($link), mysqli_error($link)); 66 break; 67 } 68 69 } 70 mysqli_free_result($res); 71 72 if (!$res = mysqli_query($link, 'SELECT id, label FROM test')) { 73 printf("[008] SELECT failed: [%d] %s\n", mysqli_errno($link), mysqli_errno($link)); 74 } 75 76 while ($row = mysqli_fetch_array($res, MYSQLI_ASSOC)) { 77 // overwrite results and check if the cache magic works 78 $row['label'] = NULL; 79 } 80 mysqli_free_result($res); 81 82 if (!$res = mysqli_query($link, 'SELECT count(*) AS num FROM test')) { 83 printf("[009] SELECT failed: [%d] %s\n", mysqli_errno($link), mysqli_errno($link)); 84 } 85 $row = mysqli_fetch_assoc($res); 86 $num = $row['num']; 87 mysqli_free_result($res); 88 89 if (!$res = mysqli_query($link, 'SELECT id, label FROM test')) { 90 printf("[010] SELECT failed: [%d] %s\n", mysqli_errno($link), mysqli_errno($link)); 91 } 92 93 $i = 0; 94 while ($row = mysqli_fetch_array($res, MYSQLI_NUM)) { 95 // overwrite results and check if the cache magic works 96 $row[0] = NULL; 97 $i++; 98 } 99 mysqli_free_result($res); 100 101 if ($i != $num) 102 printf("[011] Expecting %d results, got %d results, [%d] %s\n", 103 $num, $i, mysqli_errno($link), mysqli_error($link)); 104 105 mysqli_close($link); 106 107 print "done!"; 108?> 109--CLEAN-- 110<?php 111 require_once("clean_table.inc"); 112?> 113--EXPECT-- 114done! 115