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