1--TEST--
2mysqli_query() - unicode (cyrillic)
3--SKIPIF--
4<?php
5require_once('skipif.inc');
6require_once('skipifemb.inc');
7require_once('skipifconnectfailure.inc');
8require_once('connect.inc');
9require_once('table.inc');
10if (!$res = mysqli_query($link, "SHOW CHARACTER SET LIKE 'utf8'"))
11    die("skip UTF8 chatset seems not available");
12mysqli_free_result($res);
13mysqli_close($link);
14?>
15--FILE--
16<?php
17    include_once("connect.inc");
18
19    $tmp    = NULL;
20    $link   = NULL;
21
22    if (!is_null($tmp = @mysqli_query()))
23        printf("[001] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
24
25    if (!is_null($tmp = @mysqli_query($link)))
26        printf("[002] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
27
28    require_once('table.inc');
29
30    if (TRUE !== ($tmp = @mysqli_query($link, "set names utf8")))
31        printf("[002.5] Expecting TRUE, got %s/%s\n", gettype($tmp), $tmp);
32
33    if (NULL !== ($tmp = @mysqli_query($link, "SELECT 1 AS колона", MYSQLI_USE_RESULT, "foo")))
34        printf("[003] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
35
36    if (false !== ($tmp = mysqli_query($link, 'това не е ескюел')))
37        printf("[004] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
38
39    if (false !== ($tmp = mysqli_query($link, "SELECT 'това е ескюел, но със обратна наклонена и g'\g")))
40        printf("[005] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
41
42    if ((0 === mysqli_errno($link)) || ('' == mysqli_error($link)))
43        printf("[006] mysqli_errno()/mysqli_error should return some error\n");
44
45    if (!$res = mysqli_query($link, "SELECT 'това ескюел, но с точка и запетая' AS правилен ; "))
46        printf("[007] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
47
48    var_dump(mysqli_fetch_assoc($res));
49    mysqli_free_result($res);
50
51    if (false !== ($res = mysqli_query($link, "SELECT 'това ескюел, но с точка и запетая' AS правилен ; SHOW VARIABLES")))
52        printf("[008] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
53
54    if (mysqli_get_server_version($link) > 50000) {
55        // let's try to play with stored procedures
56        mysqli_query($link, 'DROP PROCEDURE IF EXISTS процедурка');
57        if (mysqli_query($link, 'CREATE PROCEDURE процедурка(OUT версия VARCHAR(25)) BEGIN SELECT VERSION() INTO версия; END;')) {
58            $res = mysqli_query($link, 'CALL процедурка(@version)');
59            $res = mysqli_query($link, 'SELECT @version AS п_версия');
60
61            $tmp = mysqli_fetch_assoc($res);
62            if (!is_array($tmp) || empty($tmp) || !isset($tmp['п_версия']) || ('' == $tmp['п_версия'])) {
63                printf("[008a] Expecting array [%d] %s\n", mysqli_errno($link), mysqli_error($link));
64                var_dump($tmp);
65            }
66
67            mysqli_free_result($res);
68        } else {
69            printf("[009] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
70        }
71
72        mysqli_query($link, 'DROP FUNCTION IF EXISTS функцийка');
73        if (mysqli_query($link, 'CREATE FUNCTION функцийка( параметър_версия VARCHAR(25)) RETURNS VARCHAR(25) DETERMINISTIC RETURN параметър_версия;')) {
74            $res = mysqli_query($link, 'SELECT функцийка(VERSION()) AS ф_версия');
75
76            $tmp = mysqli_fetch_assoc($res);
77            if (!is_array($tmp) || empty($tmp) || !isset($tmp['ф_версия']) || ('' == $tmp['ф_версия'])) {
78                printf("[009a] Expecting array [%d] %s\n", mysqli_errno($link), mysqli_error($link));
79                var_dump($tmp);
80            }
81
82            mysqli_free_result($res);
83        } else {
84            printf("[010] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
85        }
86    }
87
88    mysqli_close($link);
89
90    if (false !== ($tmp = mysqli_query($link, "SELECT id FROM test")))
91        printf("[014] Expecting false, got %s/%s\n", gettype($tmp), $tmp);
92
93    print "done!";
94?>
95--EXPECTF--
96array(1) {
97  ["правилен"]=>
98  string(%d) "това ескюел, но с точка и запетая"
99}
100
101Warning: mysqli_query(): Couldn't fetch mysqli in %s on line %d
102done!
103