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