Annotation of embedaddon/php/ext/mysqli/tests/mysqli_fetch_object_oo.phpt, revision 1.1.1.1

1.1       misho       1: --TEST--
                      2: mysqli_fetch_object()
                      3: --SKIPIF--
                      4: <?php
                      5: require_once('skipif.inc');
                      6: require_once('skipifemb.inc');
                      7: require_once('skipifconnectfailure.inc');
                      8: ?>
                      9: --FILE--
                     10: <?php
                     11:        require_once("connect.inc");
                     12: 
                     13:        $tmp    = NULL;
                     14:        $link   = NULL;
                     15: 
                     16:        $mysqli = new mysqli();
                     17:        $res = @new mysqli_result($mysqli);
                     18:        if (!is_null($tmp = @$res->fetch_object()))
                     19:                printf("[001] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
                     20: 
                     21:        require('table.inc');
                     22:        if (!$mysqli = new my_mysqli($host, $user, $passwd, $db, $port, $socket))
                     23:                printf("[002] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
                     24:                        $host, $user, $db, $port, $socket);
                     25: 
                     26:        if (!$res = $mysqli->query("SELECT id AS ID, label FROM test AS TEST ORDER BY id LIMIT 5")) {
                     27:                printf("[003] [%d] %s\n", $mysqli->errno, $mysqli->error);
                     28:        }
                     29: 
                     30:        if (!is_null($tmp = @$res->fetch_object($link)))
                     31:                printf("[004] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
                     32: 
                     33:        if (!is_null($tmp = @$res->fetch_object($link, $link)))
                     34:                printf("[005] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
                     35: 
                     36:        if (!is_null($tmp = @$res->fetch_object($link, $link, $link)))
                     37:                printf("[006] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
                     38: 
                     39:        $obj = mysqli_fetch_object($res);
                     40:        if (($obj->ID !== "1") || ($obj->label !== "a") || (get_class($obj) != 'stdClass')) {
                     41:                printf("[007] Object seems wrong. [%d] %s\n", $mysqli->errno, $mysqli->error);
                     42:                var_dump($obj);
                     43:        }
                     44: 
                     45:        class mysqli_fetch_object_test {
                     46: 
                     47:                public $a = null;
                     48:                public $b = null;
                     49: 
                     50:                public function toString() {
                     51:                        var_dump($this);
                     52:                }
                     53:        }
                     54: 
                     55:        $obj = $res->fetch_object('mysqli_fetch_object_test');
                     56:        if (($obj->ID !== "2") || ($obj->label !== "b") || ($obj->a !== NULL) || ($obj->b !== NULL) || (get_class($obj) != 'mysqli_fetch_object_test')) {
                     57:                printf("[008] Object seems wrong. [%d] %s\n", $mysqli->errno, $mysqli->error);
                     58:                var_dump($obj);
                     59:        }
                     60: 
                     61:        class mysqli_fetch_object_construct extends mysqli_fetch_object_test {
                     62: 
                     63:                public function __construct($a, $b) {
                     64:                        $this->a = $a;
                     65:                        $this->b = $b;
                     66:                }
                     67: 
                     68:        }
                     69: 
                     70:        $obj = $res->fetch_object('mysqli_fetch_object_construct', null);
                     71: 
                     72:        if (($obj->ID !== "3") || ($obj->label !== "c") || ($obj->a !== NULL) || ($obj->b !== NULL) || (get_class($obj) != 'mysqli_fetch_object_construct')) {
                     73:                printf("[009] Object seems wrong. [%d] %s\n", $mysqli->errno, $mysqli->error);
                     74:                var_dump($obj);
                     75:        }
                     76: 
                     77:        $obj = $res->fetch_object('mysqli_fetch_object_construct', array('a'));
                     78:        if (($obj->ID !== "4") || ($obj->label !== "d") || ($obj->a !== 'a') || ($obj->b !== NULL) || (get_class($obj) != 'mysqli_fetch_object_construct')) {
                     79:                printf("[010] Object seems wrong. [%d] %s\n", $mysqli->errno, $mysqli->error);
                     80:                var_dump($obj);
                     81:        }
                     82: 
                     83:        $obj = $res->fetch_object('mysqli_fetch_object_construct', array('a', 'b'));
                     84:        if (($obj->ID !== "5") || ($obj->label !== "e") || ($obj->a !== 'a') || ($obj->b !== 'b') || (get_class($obj) != 'mysqli_fetch_object_construct')) {
                     85:                printf("[011] Object seems wrong. [%d] %s\n", $mysqli->errno, $mysqli->error);
                     86:                var_dump($obj);
                     87:        }
                     88: 
                     89:        var_dump($res->fetch_object('mysqli_fetch_object_construct', array('a', 'b', 'c')));
                     90:        var_dump(mysqli_fetch_object($res));
                     91: 
                     92:        mysqli_free_result($res);
                     93: 
                     94:        if (!$res = mysqli_query($link, "SELECT id AS ID, label FROM test AS TEST")) {
                     95:                printf("[012] [%d] %s\n", $mysqli->errno, $mysqli->error);
                     96:        }
                     97: 
                     98:        mysqli_free_result($res);
                     99: 
                    100:        var_dump(mysqli_fetch_object($res));
                    101: 
                    102:        // Fatal error, script execution will end
                    103:        var_dump($res->fetch_object('this_class_does_not_exist'));
                    104: 
                    105:        $mysqli->close();
                    106:        print "done!";
                    107: ?>
                    108: --CLEAN--
                    109: <?php
                    110:        require_once("clean_table.inc");
                    111: ?>
                    112: --EXPECTF--
                    113: Warning: Missing argument 1 for mysqli_fetch_object_construct::__construct() in %s on line %d
                    114: 
                    115: Warning: Missing argument 2 for mysqli_fetch_object_construct::__construct() in %s on line %d
                    116: 
                    117: Notice: Undefined variable: a in %s on line %d
                    118: 
                    119: Notice: Undefined variable: b in %s on line %d
                    120: 
                    121: Warning: Missing argument 2 for mysqli_fetch_object_construct::__construct() in %s on line %d
                    122: 
                    123: Notice: Undefined variable: b in %s on line %d
                    124: NULL
                    125: NULL
                    126: 
                    127: Warning: mysqli_fetch_object(): Couldn't fetch mysqli_result in %s on line %d
                    128: NULL
                    129: 
                    130: Fatal error: Class 'this_class_does_not_exist' not found in %s on line %d

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