Annotation of embedaddon/php/ext/mysql/tests/mysql_select_db.phpt, revision 1.1

1.1     ! misho       1: --TEST--
        !             2: mysql_select_db()
        !             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: if (false !== ($tmp = @mysql_select_db($link)))
        !            16:        printf("[001] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
        !            17: 
        !            18: if (!$link = my_mysql_connect($host, $user, $passwd, $db, $port, $socket))
        !            19:        printf("[002] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
        !            20:                $host, $user, $db, $port, $socket);
        !            21: 
        !            22: if (!is_null($tmp = @mysql_select_db($db, $link, "foo")))
        !            23:        printf("[003] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
        !            24: 
        !            25: /* does not make too much sense, unless we have access to at least one more database than $db */
        !            26: if (!mysql_select_db($db, $link))
        !            27:        printf("[004] Cannot select DB %s, [%d] %s\n", $db, mysql_errno($link), mysql_error($link));
        !            28: 
        !            29: if (!$res = mysql_query("SELECT DATABASE() AS dbname", $link))
        !            30:        printf("[005] [%d] %s\n", mysql_errno($link), mysql_error($link));
        !            31: 
        !            32: if (!$row = mysql_fetch_assoc($res))
        !            33:        printf("[006] [%d] %s\n", mysql_errno($link), mysql_error($link));
        !            34: 
        !            35: if ($row['dbname'] !== (string)$db)
        !            36:        printf("[007] Expecting database '%s', found '%s'\n", $db, $row['dbname']);
        !            37: 
        !            38: var_dump($row['dbname']);
        !            39: 
        !            40: mysql_free_result($res);
        !            41: 
        !            42: if (mysql_select_db('mysql', $link)) {
        !            43:        // Yippie, a second database to play with - that's great because mysql_select_db
        !            44:        // ($db) was done by mysql__connect() already and the previous test
        !            45:        // was quite useless
        !            46:        if (!$res = mysql_query("SELECT DATABASE() AS dbname", $link))
        !            47:                printf("[008] [%d] %s\n", mysql_errno($link), mysql_error($link));
        !            48: 
        !            49:        if (!$row = mysql_fetch_assoc($res))
        !            50:                printf("[009] [%d] %s\n", mysql_errno($link), mysql_error($link));
        !            51: 
        !            52:        if (strtolower($row['dbname']) !== 'mysql')
        !            53:                printf("[010] Expecting database 'mysql', found '%s'\n", $row['dbname']);
        !            54: 
        !            55:        mysql_free_result($res);
        !            56: }
        !            57: 
        !            58: 
        !            59: var_dump(mysql_select_db('I can not imagine that this database exists', $link));
        !            60: 
        !            61: mysql_close($link);
        !            62: 
        !            63: if (false !== ($tmp = mysql_select_db($db, $link)))
        !            64:        printf("[012] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
        !            65: 
        !            66: print "done!\n";
        !            67: ?>
        !            68: --EXPECTF--
        !            69: %unicode|string%(%d) "%s"
        !            70: bool(false)
        !            71: 
        !            72: Warning: mysql_select_db(): %d is not a valid MySQL-Link resource in %s on line %d
        !            73: done!

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>