xref: /PHP-5.3/ext/mysqli/tests/065.phpt (revision 389965f1)
1--TEST--
2set character set
3--SKIPIF--
4<?php
5require_once('skipif.inc');
6require_once('skipifconnectfailure.inc');
7
8if (!function_exists('mysqli_set_charset')) {
9	die('skip mysqli_set_charset() not available');
10}
11if (version_compare(PHP_VERSION, '5.9.9', '>') == 1) {
12	die('skip set character set not functional with PHP 6 (fomerly PHP 6 && unicode.semantics=On)');
13}
14?>
15--FILE--
16<?php
17	require_once("connect.inc");
18
19	if (!$mysql = new my_mysqli($host, $user, $passwd, $db, $port, $socket))
20		printf("[001] [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
21
22	if (!mysqli_query($mysql, "SET sql_mode=''"))
23		printf("[002] Cannot set SQL-Mode, [%d] %s\n", mysqli_errno($mysql), mysqli_error($mysql));
24
25	$esc_str = chr(0xbf) . chr(0x5c);
26	$len = $charset = array();
27	$tmp = null;
28
29	if ($mysql->set_charset("latin1")) {
30		/* 5C should be escaped */
31		if (3 !== ($tmp = strlen($mysql->real_escape_string($esc_str))))
32			printf("[003] Expecting 3/int got %s/%s\n", gettype($tmp), $tmp);
33
34		if ('latin1' !== ($tmp = $mysql->character_set_name()))
35			printf("[004] Expecting latin1/string got %s/%s\n", gettype($tmp), $tmp);
36	}
37
38	if ($res = $mysql->query("SHOW CHARACTER SET LIKE 'gbk'")) {
39		$res->free_result();
40		if ($mysql->set_charset("gbk")) {
41			/* nothing should be escaped, it's a valid gbk character */
42
43			if (2 !== ($tmp = strlen($mysql->real_escape_string($esc_str))))
44					printf("[005] Expecting 2/int got %s/%s\n", gettype($tmp), $tmp);
45
46			if ('gbk' !== ($tmp = $mysql->character_set_name()))
47					printf("[005] Expecting gbk/string got %s/%s\n", gettype($tmp), $tmp);;
48		}
49	}
50	$mysql->close();
51
52	print "done!";
53?>
54--EXPECT--
55done!