1--TEST--
2mysql_num_fields()
3--SKIPIF--
4<?php
5require_once('skipif.inc');
6require_once('skipifconnectfailure.inc');
7?>
8--FILE--
9<?php
10include "connect.inc";
11
12$tmp    = NULL;
13$link   = NULL;
14
15if (!is_null($tmp = @mysql_num_fields()))
16	printf("[001] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
17
18if (NULL !== ($tmp = @mysql_num_fields($link)))
19	printf("[002] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
20
21require('table.inc');
22
23function func_test_mysql_num_fields($link, $query, $expected, $offset, $test_free = false) {
24
25if (!($res = mysql_query($query, $link))) {
26	printf("[%03d] [%d] %s\n", $offset, mysql_errno($link), mysql_error($link));
27	return;
28}
29
30if ($expected !== ($tmp = mysql_num_fields($res)))
31	printf("[%03d] Expecting %s/%d, got %s/%d\n", $offset + 1,
32	gettype($expected), $expected,
33	gettype($tmp), $tmp);
34
35mysql_free_result($res);
36
37if ($test_free && (false !== ($tmp = mysql_num_fields($res))))
38	printf("[%03d] Expecting boolean/false, got %s/%s\n", $offset + 2, gettype($tmp), $tmp);
39}
40
41func_test_mysql_num_fields($link, "SELECT 1 AS a", 1, 5);
42func_test_mysql_num_fields($link, "SELECT id, label FROM test", 2, 10);
43func_test_mysql_num_fields($link, "SELECT 1 AS a, NULL AS b, 'foo' AS c", 3, 15);
44func_test_mysql_num_fields($link, "SELECT id FROM test", 1, 20, true);
45
46mysql_close($link);
47
48print "done!";
49?>
50--CLEAN--
51<?php
52require_once("clean_table.inc");
53?>
54--EXPECTF--
55Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in %s on line %d
56
57Warning: mysql_num_fields(): %d is not a valid MySQL result resource in %s on line %d
58done!
59