xref: /PHP-5.4/ext/mysql/tests/mysql_errno.phpt (revision 5147f6cf)
1--TEST--
2mysql_errno()
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 (false !== ($tmp = @mysql_errno()))
16	printf("[001] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
17
18if (null !== ($tmp = @mysql_errno($link)))
19	printf("[002] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
20
21if (!is_null($tmp = @mysql_errno($link, 'too many args')))
22	printf("[002b] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
23
24if (!$link = my_mysql_connect($host, $user, $passwd, $db, $port, $socket)) {
25	printf("[003] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
26		$host, $user, $db, $port, $socket);
27}
28var_dump(mysql_errno($link));
29
30if (!mysql_query('DROP TABLE IF EXISTS test', $link)) {
31	printf("[004] Failed to drop old test table: [%d] %s\n", mysql_errno($link), mysql_errno($link));
32}
33
34mysql_query('SELECT * FROM test', $link);
35var_dump(mysql_errno($link));
36
37mysql_close($link);
38
39var_dump(mysql_errno($link));
40
41if ($link = @mysql_connect($host . '_unknown', $user . '_unknown', $passwd, true)) {
42	printf("[005] Can connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
43		$host . '_unknown', $user . '_unknown', $db, $port, $socket);
44} else {
45	$errno = mysql_errno();
46	if (!is_int($errno))
47		printf("[006] Expecting int/any (e.g 1046, 2005) got %s/%s\n", gettype($errno), $errno);
48
49}
50
51print "done!";
52?>
53--CLEAN--
54<?php
55require_once("clean_table.inc");
56?>
57--EXPECTF--
58int(0)
59int(%d)
60
61Warning: mysql_errno(): %d is not a valid MySQL-Link resource in %s on line %d
62bool(false)
63done!
64