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