xref: /PHP-5.4/ext/mysql/tests/mysql_error.phpt (revision f31fc6df)
1--TEST--
2mysql_error()
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_error()))
16	printf("[001] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
17
18if (NULL !== ($tmp = @mysql_error($link)))
19	printf("[002] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
20
21if (!is_null($tmp = @mysql_error($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}
28
29$tmp = mysql_error($link);
30if (!is_string($tmp) || ('' !== $tmp))
31	printf("[004] Expecting string/empty, got %s/%s. [%d] %s\n", gettype($tmp), $tmp, mysql_errno($link), mysql_error($link));
32
33if (!mysql_query('DROP TABLE IF EXISTS test', $link)) {
34	printf("[005] Failed to drop old test table: [%d] %s\n", mysql_errno($link), mysql_error($link));
35}
36
37mysql_query('SELECT * FROM test', $link);
38$tmp = mysql_error($link);
39if (!is_string($tmp) || !preg_match("/Table '\w*\.test' doesn't exist/su", $tmp))
40	printf("[006] Expecting string/[Table... doesn't exit], got %s/%s. [%d] %s\n", gettype($tmp), $tmp, mysql_errno($link), mysql_error($link));
41
42if ((version_compare(PHP_VERSION, '5.9.9', '>') == 1) && !is_unicode($tmp)) {
43	printf("[007] Expecting Unicode error message!\n");
44	var_inspect($tmp);
45}
46
47mysql_close($link);
48
49var_dump(mysql_error($link));
50
51if ($link = @mysql_connect($host . '_unknown', $user . '_unknown', $passwd, true)) {
52	printf("[008] Can connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
53		$host . '_unknown', $user . '_unknown', $db, $port, $socket);
54}
55if ('' == mysql_error())
56	printf("[009] Connect error should have been set\n");
57
58print "done!";
59?>
60--CLEAN--
61<?php
62require_once("clean_table.inc");
63?>
64--EXPECTF--
65Warning: mysql_error(): %d is not a valid MySQL-Link resource in %s on line %d
66bool(false)
67done!
68