Annotation of embedaddon/php/ext/mysql/tests/mysql_connect.phpt, revision 1.1
1.1 ! misho 1: --TEST--
! 2: mysql_connect()
! 3: --SKIPIF--
! 4: <?php
! 5: require_once('skipif.inc');
! 6: require_once('skipifconnectfailure.inc');
! 7: ?>
! 8: --FILE--
! 9: <?php
! 10: include_once "connect.inc";
! 11:
! 12: $tmp = NULL;
! 13: $link = NULL;
! 14:
! 15: // mysql_connect ( [string server [, string username [, string password [, bool new_link [, int client_flags]]]]] )
! 16: if (NULL !== ($tmp = @mysql_connect($link, $link, $link, $link, $link, $link)))
! 17: printf("[001] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
! 18:
! 19: $myhost = (is_null($socket)) ? ((is_null($port)) ? $host : $host . ':' . $port) : $host . ':' . $socket;
! 20: if (!$link = mysql_connect($myhost, $user, $passwd, true))
! 21: printf("[002] Cannot connect to the server using host=%s/%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
! 22: $host, $myhost, $user, $db, $port, $socket);
! 23:
! 24: mysql_close($link);
! 25:
! 26: if (!$link = mysql_connect($myhost, $user, $passwd, true))
! 27: printf("[003] Cannot connect to the server using host=%s/%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
! 28: $host, $myhost, $user, $db, $port, $socket);
! 29:
! 30: mysql_close();
! 31:
! 32: if ($link = mysql_connect($myhost, $user . 'unknown_really', $passwd . 'non_empty', true))
! 33: printf("[004] Can connect to the server using host=%s/%s, user=%s, passwd=***non_empty, dbname=%s, port=%s, socket=%s\n",
! 34: $host, $myhost, $user . 'unknown_really', $db, $port, $socket);
! 35:
! 36: if (false !== $link)
! 37: printf("[005] Expecting boolean/false, got %s/%s\n", gettype($link), $link);
! 38:
! 39: // Run the following tests without an anoynmous MySQL user and use a password for the test user!
! 40: ini_set('mysql.default_socket', $socket);
! 41: if (!is_null($socket)) {
! 42: if (!is_resource($link = mysql_connect($host, $user, $passwd, true))) {
! 43: printf("[006] Usage of mysql.default_socket failed\n");
! 44: } else {
! 45: mysql_close($link);
! 46: }
! 47: }
! 48:
! 49: if (!ini_get('sql.safe_mode')) {
! 50:
! 51: ini_set('mysql.default_port', $port);
! 52: if (!is_null($port)) {
! 53: if (!is_resource($link = mysql_connect($host, $user, $passwd, true))) {
! 54: printf("[007] Usage of mysql.default_port failed\n");
! 55: } else {
! 56: mysql_close($link);
! 57: }
! 58: }
! 59:
! 60: ini_set('mysql.default_password', $passwd);
! 61: if (!is_resource($link = mysql_connect($myhost, $user))) {
! 62: printf("[008] Usage of mysql.default_password failed\n");
! 63: } else {
! 64: mysql_close($link);
! 65: }
! 66: ini_set('mysql.default_user', $user);
! 67: if (!is_resource($link = mysql_connect($myhost))) {
! 68: printf("[009] Usage of mysql.default_user failed\n");
! 69: } else {
! 70: mysql_close($link);
! 71: }
! 72:
! 73: ini_set('mysql.default_host', $myhost);
! 74: if (!is_resource($link = mysql_connect())) {
! 75: printf("[010] Usage of mysql.default_host failed\n") ;
! 76: } else {
! 77: mysql_close($link);
! 78: }
! 79:
! 80: if (!is_resource($link = mysql_connect()) || !is_resource($link2 = mysql_connect())) {
! 81: printf("[011] Usage of mysql.default_host failed\n") ;
! 82: } else {
! 83: mysql_close();
! 84: mysql_close($link2);
! 85: }
! 86:
! 87: if (!stristr(PHP_OS, 'win') && !stristr(PHP_OS, 'netware')) {
! 88: ini_set('mysql.default_port', -1);
! 89: if (putenv(sprintf('MYSQL_TCP_PORT=%d', $port))) {
! 90: if (!is_resource($link = mysql_connect())) {
! 91: printf("[012] Usage of env MYSQL_TCP_PORT failed\n") ;
! 92: } else {
! 93: mysql_close($link);
! 94: }
! 95: } else if (putenv(sprintf('MYSQL_TCP_PORT=%d', $port + 1))) {
! 96: if (!is_resource($link = mysql_connect())) {
! 97: printf("[013] Usage of env MYSQL_TCP_PORT=%d should have failed\n", $port + 1) ;
! 98: mysql_close($link);
! 99: }
! 100: }
! 101: }
! 102: }
! 103:
! 104: print "done!";
! 105: ?>
! 106: --EXPECTF--
! 107: Warning: mysql_connect(): Access denied for user '%s'@'%s' (using password: YES) in %s on line %d
! 108: done!
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>