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