Annotation of embedaddon/php/ext/mysql/tests/mysql_error.phpt, revision 1.1
1.1 ! misho 1: --TEST--
! 2: mysql_error()
! 3: --SKIPIF--
! 4: <?php
! 5: require_once('skipif.inc');
! 6: require_once('skipifconnectfailure.inc');
! 7: ?>
! 8: --FILE--
! 9: <?php
! 10: include "connect.inc";
! 11:
! 12: $tmp = NULL;
! 13: $link = NULL;
! 14:
! 15: if (false !== ($tmp = @mysql_error()))
! 16: printf("[001] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
! 17:
! 18: if (NULL !== ($tmp = @mysql_error($link)))
! 19: printf("[002] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
! 20:
! 21: if (!is_null($tmp = @mysql_error($link, 'too many args')))
! 22: printf("[002b] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
! 23:
! 24: if (!$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);
! 30: if (!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:
! 33: if (!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:
! 37: mysql_query('SELECT * FROM test', $link);
! 38: $tmp = mysql_error($link);
! 39: if (!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:
! 42: if ((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:
! 47: mysql_close($link);
! 48:
! 49: var_dump(mysql_error($link));
! 50:
! 51: if ($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: }
! 55: if ('' == mysql_error())
! 56: printf("[009] Connect error should have been set\n");
! 57:
! 58: print "done!";
! 59: ?>
! 60: --CLEAN--
! 61: <?php
! 62: require_once("clean_table.inc");
! 63: ?>
! 64: --EXPECTF--
! 65: Warning: mysql_error(): %d is not a valid MySQL-Link resource in %s on line %d
! 66: bool(false)
! 67: done!
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>