Annotation of embedaddon/php/ext/mysqli/tests/mysqli_stmt_execute.phpt, revision 1.1

1.1     ! misho       1: --TEST--
        !             2: mysqli_stmt_execute()
        !             3: --SKIPIF--
        !             4: <?php
        !             5: require_once('skipif.inc');
        !             6: require_once('skipifemb.inc');
        !             7: require_once('skipifconnectfailure.inc');
        !             8: if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)) {
        !             9:        die(sprintf('skip Cannot connect to MySQL, [%d] %s.', mysqli_connect_errno(), mysqli_connect_error()));
        !            10: }
        !            11: if (mysqli_get_server_version($link) <= 40100) {
        !            12:        die(sprintf('skip Needs MySQL 4.1+, found version %d.', mysqli_get_server_version($link)));
        !            13: }
        !            14: ?>
        !            15: --FILE--
        !            16: <?php
        !            17:        require_once("connect.inc");
        !            18: 
        !            19:        $tmp    = NULL;
        !            20:        $link   = NULL;
        !            21: 
        !            22:        if (!is_null($tmp = @mysqli_stmt_execute()))
        !            23:                printf("[001] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
        !            24: 
        !            25:        if (!is_null($tmp = @mysqli_stmt_execute($link)))
        !            26:                printf("[002] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
        !            27: 
        !            28:        require('table.inc');
        !            29: 
        !            30:        if (!$stmt = mysqli_stmt_init($link))
        !            31:                printf("[003] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
        !            32: 
        !            33:        // stmt object status test
        !            34:        if (NULL !== ($tmp = mysqli_stmt_execute($stmt)))
        !            35:                printf("[004] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
        !            36: 
        !            37:        if (mysqli_stmt_prepare($stmt, "SELECT i_do_not_exist_believe_me FROM test ORDER BY id"))
        !            38:                printf("[005] Statement should have failed!\n");
        !            39: 
        !            40:        // stmt object status test
        !            41:        if (NULL !== ($tmp = mysqli_stmt_execute($stmt)))
        !            42:                printf("[006] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
        !            43: 
        !            44:        if (!mysqli_stmt_prepare($stmt, "SELECT id FROM test ORDER BY id LIMIT 1"))
        !            45:                printf("[007] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
        !            46: 
        !            47:        if (true !== ($tmp = mysqli_stmt_execute($stmt)))
        !            48:                printf("[008] Expecting boolean/true, got %s/%s. [%d] %s\n",
        !            49:                        gettype($tmp), $tmp, mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
        !            50: 
        !            51:        if (!mysqli_stmt_prepare($stmt, "INSERT INTO test(id, label) VALUES (?, ?)"))
        !            52:                printf("[009] [%d] %s\n", mysqli_stmt_execute($stmt), mysqli_stmt_execute($stmt));
        !            53: 
        !            54:        // no input variables bound
        !            55:        if (false !== ($tmp = mysqli_stmt_execute($stmt)))
        !            56:                printf("[010] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
        !            57: 
        !            58:        $id = 100;
        !            59:        $label = "z";
        !            60:        if (!mysqli_stmt_bind_param($stmt, "is", $id, $label))
        !            61:                printf("[011] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
        !            62: 
        !            63:        if (true !== ($tmp = mysqli_stmt_execute($stmt)))
        !            64:                printf("[012] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
        !            65: 
        !            66:        // calling reset between executions
        !            67:        mysqli_stmt_close($stmt);
        !            68:        if (!$stmt = mysqli_stmt_init($link))
        !            69:                printf("[013] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
        !            70: 
        !            71:        if (!mysqli_stmt_prepare($stmt, "SELECT id FROM test ORDER BY id LIMIT ?"))
        !            72:                printf("[014] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
        !            73: 
        !            74:        $limit = 1;
        !            75:        if (!mysqli_stmt_bind_param($stmt, "i", $limit))
        !            76:                printf("[015] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
        !            77: 
        !            78:        if (true !== ($tmp = mysqli_stmt_execute($stmt)))
        !            79:                printf("[016] Expecting boolean/true, got %s/%s. [%d] %s\n",
        !            80:                        gettype($tmp), $tmp, mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
        !            81: 
        !            82:        $id = null;
        !            83:        if (!mysqli_stmt_bind_result($stmt, $id) || !mysqli_stmt_fetch($stmt))
        !            84:                printf("[017] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
        !            85: 
        !            86:        if ($id !== 1)
        !            87:                printf("[018] Expecting int/1 got %s/%s\n", gettype($id), $id);
        !            88: 
        !            89:        if (true !== ($tmp = mysqli_stmt_reset($stmt)))
        !            90:                printf("[019] Expecting boolean/true, got %s/%s. [%d] %s\n",
        !            91:                        gettype($tmp), $tmp, mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
        !            92: 
        !            93:        if (true !== ($tmp = mysqli_stmt_execute($stmt)))
        !            94:                printf("[020] Expecting boolean/true after reset to prepare status, got %s/%s. [%d] %s\n",
        !            95:                        gettype($tmp), $tmp, mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
        !            96: 
        !            97:        $id = null;
        !            98:        if (!mysqli_stmt_fetch($stmt))
        !            99:                printf("[021] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
        !           100: 
        !           101:        if ($id !== 1)
        !           102:                printf("[022] Expecting int/1 got %s/%s\n", gettype($id), $id);
        !           103: 
        !           104:        mysqli_stmt_close($stmt);
        !           105:        if (!$stmt = mysqli_stmt_init($link))
        !           106:                printf("[023] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
        !           107: 
        !           108:        if (!mysqli_stmt_prepare($stmt, "SELECT id FROM test ORDER BY id LIMIT 1"))
        !           109:                printf("[024] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
        !           110: 
        !           111:        if (true !== ($tmp = mysqli_stmt_execute($stmt)))
        !           112:                printf("[025] Expecting boolean/true, got %s/%s. [%d] %s\n",
        !           113:                        gettype($tmp), $tmp, mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
        !           114: 
        !           115:        if (true !== ($tmp = mysqli_stmt_reset($stmt)))
        !           116:                printf("[026] Expecting boolean/true, got %s/%s. [%d] %s\n",
        !           117:                        gettype($tmp), $tmp, mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
        !           118: 
        !           119:        var_dump(mysqli_stmt_execute($stmt));
        !           120:        var_dump(mysqli_stmt_fetch($stmt));
        !           121: 
        !           122:        mysqli_kill($link, mysqli_thread_id($link));
        !           123: 
        !           124:        if (false !== ($tmp = mysqli_stmt_execute($stmt)))
        !           125:                printf("[027] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
        !           126: 
        !           127:        mysqli_stmt_close($stmt);
        !           128: 
        !           129:        if (NULL !== ($tmp = mysqli_stmt_execute($stmt)))
        !           130:                printf("[028] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
        !           131: 
        !           132:        mysqli_close($link);
        !           133:        print "done!";
        !           134: ?>
        !           135: --CLEAN--
        !           136: <?php
        !           137:        require_once("clean_table.inc");
        !           138: ?>
        !           139: --EXPECTF--
        !           140: Warning: mysqli_stmt_execute(): invalid object or resource mysqli_stmt
        !           141:  in %s on line %d
        !           142: 
        !           143: Warning: mysqli_stmt_execute(): invalid object or resource mysqli_stmt
        !           144:  in %s on line %d
        !           145: bool(true)
        !           146: bool(true)
        !           147: [027] Expecting boolean/false, got boolean/1
        !           148: 
        !           149: Warning: mysqli_stmt_execute(): Couldn't fetch mysqli_stmt in %s on line %d
        !           150: done!

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