1--TEST--
2mysqli_result->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	require('table.inc');
17
18	if (!$mysqli = new mysqli($host, $user, $passwd, $db, $port, $socket))
19	printf("[001] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
20		$host, $user, $db, $port, $socket);
21
22	$res = new mysqli_result($mysqli);
23	if (NULL !== ($tmp = @$res->data_seek(0)))
24		printf("[002] Expecting NULL/NULL, got %s/%s\n", gettype($tmp), $tmp);
25
26	if (!$res = $mysqli->query('SELECT * FROM test ORDER BY id LIMIT 4', MYSQLI_STORE_RESULT))
27		printf("[003] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
28
29	if (NULL !== ($tmp = @$res->data_seek()))
30		printf("[004] Expecting NULL/NULL, got %s/%s\n", gettype($tmp), $tmp);
31
32	if (NULL !== ($tmp = @$res->data_seek($link)))
33		printf("[005] Expecting NULL/NULL, got %s/%s\n", gettype($tmp), $tmp);
34
35	if (NULL !== ($tmp = @$res->data_seek($link, $link)))
36		printf("[006] Expecting NULL/NULL, got %s/%s\n", gettype($tmp), $tmp);
37
38	if (true !== ($tmp = $res->data_seek(3)))
39		printf("[007] Expecting boolean/true, got %s/%s\n", gettype($tmp), $tmp);
40
41	$row = $res->fetch_assoc();
42	if (4 != $row['id'])
43		printf("[008] Expecting record 4/d, got record %s/%s\n", $row['id'], $row['label']);
44
45	if (true !== ($tmp = $res->data_seek(0)))
46		printf("[009] Expecting boolean/true, got %s/%s\n", gettype($tmp), $tmp);
47
48	$row = $res->fetch_assoc();
49	if (1 != $row['id'])
50		printf("[010] Expecting record 1/a, got record %s/%s\n", $row['id'], $row['label']);
51
52	if (false !== ($tmp = $res->data_seek(4)))
53		printf("[011] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
54
55	if (false !== ($tmp = $res->data_seek(-1)))
56		printf("[012] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
57
58	$res->free_result();
59
60	if (!$res = $mysqli->query('SELECT * FROM test ORDER BY id', MYSQLI_USE_RESULT))
61		printf("[013] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
62
63	if (false !== ($tmp = $res->data_seek(3)))
64		printf("[014] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
65
66	$res->free_result();
67
68	if (NULL !== ($tmp = $res->data_seek(1)))
69		printf("[015] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
70
71	$mysqli->close();
72
73	print "done!";
74?>
75--CLEAN--
76<?php
77	require_once("clean_table.inc");
78?>
79--EXPECTF--
80Warning: mysqli_result::data_seek(): Function cannot be used with MYSQL_USE_RESULT in %s on line %d
81
82Warning: mysqli_result::data_seek(): Couldn't fetch mysqli_result in %s on line %d
83done!
84