1--TEST--
2mysqli_get_client_stats() - skipped rows
3--INI--
4mysqlnd.collect_statistics="1"
5mysqlnd.collect_memory_statistics="1"
6--SKIPIF--
7<?PHP
8require_once('skipif.inc');
9require_once('skipifconnectfailure.inc');
10if (!function_exists('mysqli_get_client_stats')) {
11    die("skip only available with mysqlnd");
12}
13?>
14--FILE--
15<?php
16    require_once('connect.inc');
17    require_once('table.inc');
18
19    if (!$res = mysqli_query($link, 'SELECT id FROM test', MYSQLI_STORE_RESULT))
20        printf("[001] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
21
22    $num_rows = mysqli_num_rows($res);
23    assert($num_rows > 2);
24    mysqli_free_result($res);
25
26    $before = mysqli_get_client_stats();
27    printf("BEFORE: rows_skipped_normal = %d\n", $before['rows_skipped_normal']);
28
29    if (!$res = mysqli_query($link, 'SELECT id FROM test', MYSQLI_USE_RESULT))
30        printf("[002] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
31
32    /* fetch all rows but the last one */
33    for ($i = 0; $i < $num_rows - 1; $i++)
34        $row = mysqli_fetch_assoc($res);
35
36    /* enforce implicit cleaning of the wire and skipping the last row */
37    mysqli_free_result($res);
38    $after = mysqli_get_client_stats();
39    printf("AFTER: rows_skipped_normal = %d\n", $after['rows_skipped_normal']);
40
41    if ($after['rows_skipped_normal'] != $before['rows_skipped_normal'] + 1)
42        printf("Statistics should show an increase of 1 for rows_skipped_normal, ".
43                "but before=%d after=%d\n", $before['rows_skipped_normal'], $after['rows_skipped_normal']);
44
45    mysqli_close($link);
46    print "done!";
47?>
48--EXPECTF--
49BEFORE: rows_skipped_normal = %d
50AFTER: rows_skipped_normal = %d
51done!
52