1--TEST--
2mysqli_stmt_field_counts()
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_field_count()))
17		printf("[001] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
18
19	if (!is_null($tmp = @mysqli_stmt_field_count($link)))
20		printf("[002] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
21
22	require('table.inc');
23
24	$stmt = mysqli_stmt_init($link);
25	if (false !== ($tmp = mysqli_stmt_field_count($stmt)))
26		printf("[003] Expecting false, got %s/%s\n", gettype($tmp), $tmp);
27
28	if (mysqli_stmt_prepare($stmt, ''))
29		printf("[004] Prepare should fail for an empty statement\n");
30
31	if (false !== ($tmp = mysqli_stmt_field_count($stmt)))
32		printf("[005] Expecting false, got %s/%s\n", gettype($tmp), $tmp);
33
34	if (!mysqli_stmt_prepare($stmt, 'SELECT 1'))
35		printf("[006] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
36	if (1 !== ($tmp = mysqli_stmt_field_count($stmt)))
37		printf("[007] Expecting int/1, got %s/%s\n", gettype($tmp), $tmp);
38
39	if (!mysqli_stmt_prepare($stmt, 'SELECT 1, 2'))
40		printf("[008] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
41	if (2 !== ($tmp = mysqli_stmt_field_count($stmt)))
42		printf("[009] Expecting int/2, got %s/%s\n", gettype($tmp), $tmp);
43
44	if (!mysqli_stmt_prepare($stmt, 'SELECT id, label FROM test'))
45		printf("[010] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
46	if (2 !== ($tmp = mysqli_stmt_field_count($stmt)))
47		printf("[011] Expecting int/2, got %s/%s\n", gettype($tmp), $tmp);
48
49	if (!mysqli_stmt_prepare($stmt, 'SELECT label FROM test') ||
50		!mysqli_stmt_execute($stmt))
51		printf("[012] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
52	if (1 !== ($tmp = mysqli_stmt_field_count($stmt)))
53		printf("[013] Expecting int/1, got %s/%s\n", gettype($tmp), $tmp);
54
55	$label = null;
56	if (mysqli_stmt_bind_param($stmt, "s", $label))
57		printf("[014] expected error - got ok\n");
58	while (mysqli_stmt_fetch($stmt))
59		if (1 !== ($tmp = mysqli_stmt_field_count($stmt)))
60			printf("[015] Expecting int/1, got %s/%s\n", gettype($tmp), $tmp);
61
62	if (!mysqli_stmt_prepare($stmt, 'INSERT INTO test(id) VALUES (100)'))
63		printf("[016] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
64	if (0 !== ($tmp = mysqli_stmt_field_count($stmt)))
65		printf("[017] Expecting int/0, got %s/%s\n", gettype($tmp), $tmp);
66
67	if (!mysqli_stmt_prepare($stmt, "UPDATE test SET label = 'z' WHERE id = 1") ||
68		!mysqli_stmt_execute($stmt))
69		printf("[018] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
70
71	if (0 !== ($tmp = mysqli_stmt_field_count($stmt)))
72		printf("[019] Expecting int/0, got %s/%s\n", gettype($tmp), $tmp);
73
74	mysqli_stmt_close($stmt);
75
76	if (mysqli_stmt_prepare($stmt, 'SELECT id FROM test'))
77		printf("[020] Prepare should fail, statement has been closed\n");
78
79	if (false !== ($tmp = mysqli_stmt_field_count($stmt)))
80		printf("[021] Expecting false, got %s/%s\n", gettype($tmp), $tmp);
81
82	mysqli_close($link);
83
84	print "done!";
85?>
86--CLEAN--
87<?php
88	require_once("clean_table.inc");
89?>
90--EXPECTF--
91Warning: mysqli_stmt_field_count(): invalid object or resource mysqli_stmt
92 in %s on line %d
93
94Warning: mysqli_stmt_field_count(): invalid object or resource mysqli_stmt
95 in %s on line %d
96
97Warning: mysqli_stmt_bind_param(): Number of variables doesn't match number of parameters in prepared statement in %s on line %d
98
99Warning: mysqli_stmt_prepare(): Couldn't fetch mysqli_stmt in %s on line %d
100
101Warning: mysqli_stmt_field_count(): Couldn't fetch mysqli_stmt in %s on line %d
102done!
103