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