1--TEST-- 2mysqli_result->data_seek() 3--EXTENSIONS-- 4mysqli 5--SKIPIF-- 6<?php 7require_once('skipifconnectfailure.inc'); 8?> 9--FILE-- 10<?php 11 require_once("connect.inc"); 12 require('table.inc'); 13 14 if (!$mysqli = new mysqli($host, $user, $passwd, $db, $port, $socket)) 15 printf("[001] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n", 16 $host, $user, $db, $port, $socket); 17 18 $res = new mysqli_result($mysqli); 19 20 try { 21 $res->data_seek(0); 22 } catch (Error $exception) { 23 echo $exception->getMessage() . "\n"; 24 } 25 26 if (!$res = $mysqli->query('SELECT * FROM test ORDER BY id LIMIT 4', MYSQLI_STORE_RESULT)) 27 printf("[003] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 28 29 if (true !== ($tmp = $res->data_seek(3))) 30 printf("[007] Expecting boolean/true, got %s/%s\n", gettype($tmp), $tmp); 31 32 $row = $res->fetch_assoc(); 33 if (4 != $row['id']) 34 printf("[008] Expecting record 4/d, got record %s/%s\n", $row['id'], $row['label']); 35 36 if (true !== ($tmp = $res->data_seek(0))) 37 printf("[009] Expecting boolean/true, got %s/%s\n", gettype($tmp), $tmp); 38 39 $row = $res->fetch_assoc(); 40 if (1 != $row['id']) 41 printf("[010] Expecting record 1/a, got record %s/%s\n", $row['id'], $row['label']); 42 43 if (false !== ($tmp = $res->data_seek(4))) 44 printf("[011] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp); 45 46 try { 47 $res->data_seek(-1); 48 } catch (\ValueError $e) { 49 echo $e->getMessage() . \PHP_EOL; 50 } 51 52 $res->free_result(); 53 54 if (!$res = $mysqli->query('SELECT * FROM test ORDER BY id', MYSQLI_USE_RESULT)) 55 printf("[013] [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 56 57 try { 58 var_dump($res->data_seek(3)); 59 } catch (\Error $e) { 60 echo $e->getMessage() . \PHP_EOL; 61 } 62 63 $res->free_result(); 64 65 try { 66 $res->data_seek(1); 67 } catch (Error $exception) { 68 echo $exception->getMessage() . "\n"; 69 } 70 71 $mysqli->close(); 72 73 print "done!"; 74--CLEAN-- 75<?php 76 require_once("clean_table.inc"); 77?> 78--EXPECT-- 79mysqli_result object is already closed 80mysqli_result::data_seek(): Argument #1 ($offset) must be greater than or equal to 0 81mysqli_result::data_seek() cannot be used in MYSQLI_USE_RESULT mode 82mysqli_result object is already closed 83done! 84