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