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