Files
php-src/ext/mysqli/tests/mysqli_query_unicode.phpt
Christoph M. Becker 7a9120e5f3 Avoid multiple connects in SKIPIF sections (GH-15470)
Besides checking for the ability to connect to the MySQL server, some
tests require additional checks (e.g. to be able to check for the
server's version) as skip condition.  There is no need, though, to
connect twice; instead we introduce `mysqli_connect_or_skip()` in
test_helpers.inc, which `die()`s with an appropriate error message, if
the connection can't be established, or returns the connection link
otherwise.

Co-authored-by: Kamil Tekiela <tekiela246@gmail.com>
2024-08-18 13:41:09 +02:00

93 lines
3.7 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

--TEST--
mysqli_query() - unicode (cyrillic)
--EXTENSIONS--
mysqli
--SKIPIF--
<?php
require_once 'skipifconnectfailure.inc';
?>
--FILE--
<?php
require_once 'table.inc';
if (TRUE !== ($tmp = @mysqli_query($link, "set names utf8")))
printf("[002.5] Expecting TRUE, got %s/%s\n", gettype($tmp), $tmp);
if (false !== ($tmp = mysqli_query($link, 'това не е ескюел')))
printf("[004] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
if (false !== ($tmp = mysqli_query($link, "SELECT 'това е ескюел, но със обратна наклонена и g'\g")))
printf("[005] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
if ((0 === mysqli_errno($link)) || ('' == mysqli_error($link)))
printf("[006] mysqli_errno()/mysqli_error should return some error\n");
if (!$res = mysqli_query($link, "SELECT 'това ескюел, но с точка и запетая' AS правилен ; "))
printf("[007] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
var_dump(mysqli_fetch_assoc($res));
mysqli_free_result($res);
if (false !== ($res = mysqli_query($link, "SELECT 'това ескюел, но с точка и запетая' AS правилен ; SHOW VARIABLES")))
printf("[008] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
if (mysqli_get_server_version($link) > 50000) {
// let's try to play with stored procedures
mysqli_query($link, 'DROP PROCEDURE IF EXISTS процедурка');
if (mysqli_query($link, 'CREATE PROCEDURE процедурка(OUT версия VARCHAR(25)) BEGIN SELECT VERSION() INTO версия; END;')) {
mysqli_query($link, 'CALL процедурка(@version)');
$res = mysqli_query($link, 'SELECT @version AS п_версия');
$tmp = mysqli_fetch_assoc($res);
if (!is_array($tmp) || empty($tmp) || !isset($tmp['п_версия']) || ('' == $tmp['п_версия'])) {
printf("[008a] Expecting array [%d] %s\n", mysqli_errno($link), mysqli_error($link));
var_dump($tmp);
}
mysqli_free_result($res);
} else {
printf("[009] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
}
mysqli_query($link, 'DROP FUNCTION IF EXISTS функцийка');
if (mysqli_query($link, 'CREATE FUNCTION функцийка( параметърерсия VARCHAR(25)) RETURNS VARCHAR(25) DETERMINISTIC RETURN параметърерсия;')) {
$res = mysqli_query($link, 'SELECT функцийка(VERSION()) AS ф_версия');
$tmp = mysqli_fetch_assoc($res);
if (!is_array($tmp) || empty($tmp) || !isset($tmp['ф_версия']) || ('' == $tmp['ф_версия'])) {
printf("[009a] Expecting array [%d] %s\n", mysqli_errno($link), mysqli_error($link));
var_dump($tmp);
}
mysqli_free_result($res);
} else {
printf("[010] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
}
}
mysqli_close($link);
try {
mysqli_query($link, "SELECT id FROM test");
} catch (Error $exception) {
echo $exception->getMessage() . "\n";
}
print "done!";
?>
--CLEAN--
<?php
require_once 'connect.inc';
$link = new mysqli($host, $user, $passwd, $db, $port, $socket);
$link->query('DROP PROCEDURE IF EXISTS процедурка');
$link->query('DROP FUNCTION IF EXISTS функцийка');
$link->close();
?>
--EXPECTF--
array(1) {
["правилен"]=>
string(%d) "това ескюел, но с точка и запетая"
}
mysqli object is already closed
done!