1--TEST--
2mysqli_stmt_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 (!$stmt = mysqli_stmt_init($link))
14        printf("[003] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
15
16    try {
17        mysqli_stmt_data_seek($stmt, 1);
18    } catch (Error $exception) {
19        echo $exception->getMessage() . "\n";
20    }
21
22    if (!mysqli_stmt_prepare($stmt, "SELECT id FROM test ORDER BY id"))
23        printf("[005] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
24
25    if (true !== ($tmp = mysqli_stmt_execute($stmt)))
26        printf("[006] Expecting boolean/true, got %s/%s\n", gettype($tmp), $tmp);
27
28
29    $id = null;
30    if (!mysqli_stmt_bind_result($stmt, $id))
31        printf("[007] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
32
33    if (!mysqli_stmt_store_result($stmt))
34        printf("[008] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
35
36    mysqli_stmt_data_seek($stmt, 2);
37
38    if (!mysqli_stmt_fetch($stmt))
39        printf("[010] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
40
41    var_dump($id);
42
43    mysqli_stmt_data_seek($stmt, 0);
44
45    if (!mysqli_stmt_fetch($stmt))
46        printf("[012] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
47
48    var_dump($id);
49
50    mysqli_stmt_data_seek($stmt, mysqli_stmt_num_rows($stmt) + 100);
51
52    if (mysqli_stmt_fetch($stmt))
53        printf("[014] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
54
55    var_dump($id);
56
57    try {
58        mysqli_stmt_data_seek($stmt, -1);
59    } catch (\ValueError $e) {
60        echo $e->getMessage() . \PHP_EOL;
61    }
62
63    if (mysqli_stmt_fetch($stmt))
64        printf("[016] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
65
66    var_dump($id);
67
68    mysqli_stmt_close($stmt);
69
70    try {
71        mysqli_stmt_data_seek($stmt, 0);
72    } catch (Error $exception) {
73        echo $exception->getMessage() . "\n";
74    }
75
76    mysqli_close($link);
77    print "done!";
78?>
79--CLEAN--
80<?php
81    require_once 'clean_table.inc';
82?>
83--EXPECT--
84mysqli_stmt object is not fully initialized
85int(3)
86int(1)
87int(1)
88mysqli_stmt_data_seek(): Argument #2 ($offset) must be greater than or equal to 0
89int(1)
90mysqli_stmt object is already closed
91done!
92