1--TEST--
2mysqli_get_client_stats() - PS
3--EXTENSIONS--
4mysqli
5--SKIPIF--
6<?PHP
7require_once 'skipifconnectfailure.inc';
8?>
9--INI--
10mysqlnd.collect_statistics=1
11mysqlnd.collect_memory_statistics=1
12--FILE--
13<?php
14    require_once 'connect.inc';
15    require_once 'table.inc';
16
17    $stats = mysqli_get_client_stats();
18    printf("BEGINNING: rows_fetched_from_client_ps_unbuffered = %d\n",	$stats['rows_fetched_from_client_ps_unbuffered']);
19    printf("BEGINNING: rows_fetched_from_client_ps_buffered = %d\n",	$stats['rows_fetched_from_client_ps_buffered']);
20    printf("BEGINNING: rows_fetched_from_client_ps_cursor = %d\n",	$stats['rows_fetched_from_client_ps_cursor']);
21
22    if (!$stmt = mysqli_stmt_init($link))
23        printf("[001] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
24
25    $id = null;
26    if (!mysqli_stmt_prepare($stmt, 'SELECT id FROM test') ||
27            !mysqli_stmt_execute($stmt) ||
28            !mysqli_stmt_store_result($stmt) ||
29            !mysqli_stmt_bind_result($stmt, $id))
30        printf("[002] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
31
32    $num_rows = 0;
33    while (mysqli_stmt_fetch($stmt))
34        $num_rows++;
35
36    mysqli_stmt_free_result($stmt);
37
38    $after = mysqli_get_client_stats();
39
40    if ($after['rows_fetched_from_client_ps_unbuffered'] != $stats['rows_fetched_from_client_ps_unbuffered'])
41        printf("[003] Unbuffered rows got increased after buffered PS, expecting %d got %d.\n",
42            $stats['rows_fetched_from_client_ps_unbuffered'],
43            $after['rows_fetched_from_client_ps_unbuffered']);
44
45    $stats['rows_fetched_from_client_ps_buffered'] += $num_rows;
46    if ($after['rows_fetched_from_client_ps_buffered'] != $stats['rows_fetched_from_client_ps_buffered'] )
47        printf("[005] Buffered rows should be %d got %d.\n",
48            $stats['rows_fetched_from_client_ps_buffered'],
49            $after['rows_fetched_from_client_ps_buffered']);
50
51    $stats = $after;
52    printf("BUFFERED: rows_fetched_from_client_ps_unbuffered = %d\n",	$stats['rows_fetched_from_client_ps_unbuffered']);
53    printf("BUFFERED: rows_fetched_from_client_ps_buffered = %d\n",	$stats['rows_fetched_from_client_ps_buffered']);
54    printf("BUFFERED: rows_fetched_from_client_ps_cursor = %d\n",	$stats['rows_fetched_from_client_ps_cursor']);
55
56    $id = null;
57    if (!mysqli_stmt_prepare($stmt, 'SELECT id FROM test') ||
58            !mysqli_stmt_execute($stmt) ||
59            !mysqli_stmt_bind_result($stmt, $id))
60        printf("[006] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
61
62    $num_rows = 0;
63    while (mysqli_stmt_fetch($stmt))
64        $num_rows++;
65
66    $after = mysqli_get_client_stats();
67    $stats['rows_fetched_from_client_ps_unbuffered'] += $num_rows;
68    if ($after['rows_fetched_from_client_ps_unbuffered'] != $stats['rows_fetched_from_client_ps_unbuffered'])
69        printf("[007] Unbuffered rows should be %d got %d.\n",
70            $stats['rows_fetched_from_client_ps_unbuffered'],
71            $after['rows_fetched_from_client_ps_unbuffered']);
72
73    if ($after['rows_fetched_from_client_ps_buffered'] != $stats['rows_fetched_from_client_ps_buffered'] )
74        printf("[005] Buffered rows should be unchanged, expecting %d got %d.\n",
75            $stats['rows_fetched_from_client_ps_buffered'],
76            $after['rows_fetched_from_client_ps_buffered']);
77
78    mysqli_stmt_free_result($stmt);
79    mysqli_stmt_close($stmt);
80
81    $stats = $after;
82    printf("UNBUFFERED: rows_fetched_from_client_ps_unbuffered = %d\n",	$stats['rows_fetched_from_client_ps_unbuffered']);
83    printf("UNBUFFERED: rows_fetched_from_client_ps_buffered = %d\n",	$stats['rows_fetched_from_client_ps_buffered']);
84    printf("UNBUFFERED: rows_fetched_from_client_ps_cursor = %d\n",	$stats['rows_fetched_from_client_ps_cursor']);
85
86    mysqli_close($link);
87    print "done!";
88?>
89--CLEAN--
90<?php
91	require_once 'clean_table.inc';
92?>
93--EXPECTF--
94BEGINNING: rows_fetched_from_client_ps_unbuffered = %d
95BEGINNING: rows_fetched_from_client_ps_buffered = %d
96BEGINNING: rows_fetched_from_client_ps_cursor = 0
97BUFFERED: rows_fetched_from_client_ps_unbuffered = %d
98BUFFERED: rows_fetched_from_client_ps_buffered = %d
99BUFFERED: rows_fetched_from_client_ps_cursor = 0
100UNBUFFERED: rows_fetched_from_client_ps_unbuffered = %d
101UNBUFFERED: rows_fetched_from_client_ps_buffered = %d
102UNBUFFERED: rows_fetched_from_client_ps_cursor = 0
103done!
104