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