1--TEST--
2mysqli_stmt_data_seek()
3--SKIPIF--
4<?php
5require_once('skipif.inc');
6require_once('skipifemb.inc');
7require_once('skipifconnectfailure.inc');
8?>
9--FILE--
10<?php
11	require_once("connect.inc");
12
13	$tmp    = NULL;
14	$link   = NULL;
15
16	if (!is_null($tmp = @mysqli_stmt_data_seek()))
17		printf("[001] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
18
19	if (!is_null($tmp = @mysqli_stmt_data_seek($link)))
20		printf("[002] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
21
22	require('table.inc');
23
24	if (!$stmt = mysqli_stmt_init($link))
25		printf("[003] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
26
27	if (!is_null($tmp = mysqli_stmt_data_seek($stmt, 1)))
28		printf("[004] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
29
30	if (!mysqli_stmt_prepare($stmt, "SELECT id FROM test ORDER BY id"))
31		printf("[005] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
32
33	if (true !== ($tmp = mysqli_stmt_execute($stmt)))
34		printf("[006] Expecting boolean/true, got %s/%s\n", gettype($tmp), $tmp);
35
36
37	$id = null;
38	if (!mysqli_stmt_bind_result($stmt, $id))
39		printf("[007] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
40
41	if (!mysqli_stmt_store_result($stmt))
42		printf("[008] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
43
44	if (!is_null($tmp = mysqli_stmt_data_seek($stmt, 2)))
45		printf("[009] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
46
47	if (!mysqli_stmt_fetch($stmt))
48		printf("[010] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
49
50	var_dump($id);
51
52	if (!is_null($tmp = mysqli_stmt_data_seek($stmt, 0)))
53		printf("[011] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
54
55	if (!mysqli_stmt_fetch($stmt))
56		printf("[012] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
57
58	var_dump($id);
59
60	if (!is_null($tmp = mysqli_stmt_data_seek($stmt, mysqli_stmt_num_rows($stmt) + 100)))
61		printf("[013] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
62
63	if (mysqli_stmt_fetch($stmt))
64		printf("[014] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
65
66	var_dump($id);
67
68	if (false !== ($tmp = mysqli_stmt_data_seek($stmt, -1)))
69		printf("[015] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
70
71	if (mysqli_stmt_fetch($stmt))
72		printf("[016] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
73
74	var_dump($id);
75
76	mysqli_stmt_close($stmt);
77
78	if (NULL !== ($tmp = mysqli_stmt_data_seek($stmt, 0)))
79		printf("[017] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
80
81	mysqli_close($link);
82	print "done!";
83?>
84--CLEAN--
85<?php
86	require_once("clean_table.inc");
87?>
88--EXPECTF--
89Warning: mysqli_stmt_data_seek(): invalid object or resource mysqli_stmt
90 in %s on line %d
91int(3)
92int(1)
93int(1)
94
95Warning: mysqli_stmt_data_seek(): Offset must be positive in %s on line %d
96int(1)
97
98Warning: mysqli_stmt_data_seek(): Couldn't fetch mysqli_stmt in %s on line %d
99done!
100