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