xref: /PHP-5.5/ext/mysql/tests/mysql_db_name.phpt (revision b7091aaf)
1--TEST--
2mysql_db_name()
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 (NULL !== ($tmp = @mysql_db_name()))
16	printf("[001] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
17
18if (NULL !== ($tmp = @mysql_db_name($link, $link)))
19	printf("[002] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
20
21require('table.inc');
22
23if (!$res = @mysql_list_dbs($link))
24	printf("[003] [%d] %s\n", mysql_errno($link), mysql_error($link));
25
26if (!$num = mysql_num_rows($res))
27	printf("[004] Empty database list? [%d] %s\n", mysql_errno($link), mysql_error($link));
28
29if (false !== ($tmp = mysql_db_name($res, -1)))
30	printf("[005] Expecting boolean/false, got %s/%s. [%d] %s\n",
31		gettype($tmp), $tmp, mysql_errno($link), mysql_error($link));
32
33if (false !== ($tmp = mysql_db_name($res, $num + 1)))
34	printf("[006] Expecting boolean/false, got %s/%s. [%d] %s\n",
35		gettype($tmp), $tmp, mysql_errno($link), mysql_error($link));
36
37$unicode = (boolean)(version_compare(PHP_VERSION, '5.9.9', '>') == 1);
38for ($i = 0; $i < $num; $i++) {
39	if ('' === ($dbname = mysql_db_name($res, $i)))
40		printf("[%03d] Got empty database name! [%d] %s\n",
41			(($i * 2) + 1) + 6, mysql_errno($link), mysql_error($link));
42
43	if ($unicode && !is_unicode($dbname)) {
44		printf("[%03d] Expecting unicode string! [%d] %s\n",
45			(($i * 2) + 2) + 6, mysql_errno($link), mysql_error($link));
46		var_inspect($dbname);
47	}
48}
49
50mysql_free_result($res);
51
52if (false !== ($tmp = mysql_db_name($res, $num)))
53	printf("[999] Expecting boolean/false, got %s/%s. [%d] %s\n",
54		gettype($tmp), $tmp, mysql_errno($link), mysql_error($link));
55
56mysql_close($link);
57
58print "done!\n";
59?>
60--EXPECTF--
61Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in %s on line %d
62
63Warning: mysql_db_name(): Unable to jump to row -1 on MySQL result index %d in %s on line %d
64
65Warning: mysql_db_name(): Unable to jump to row %d on MySQL result index %d in %s on line %d
66
67Warning: mysql_db_name(): %d is not a valid MySQL result resource in %s on line %d
68done!
69