1--TEST-- 2mysqli_real_escape_string() - gb2312 3--EXTENSIONS-- 4mysqli 5--SKIPIF-- 6<?php 7require_once __DIR__ . '/test_setup/test_helpers.inc'; 8$link = mysqli_connect_or_skip(); 9if (!mysqli_set_charset($link, 'gb2312')) 10 die(sprintf("skip Cannot set charset 'gb2312'")); 11?> 12--FILE-- 13<?php 14 15 require_once 'connect.inc'; 16 if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)) 17{ 18 printf("[001] Cannot connect to the server using host=%s, user=%s, 19passwd=***, dbname=%s, port=%s, socket=%s - [%d] %s\n", $host, $user, $db, 20$port, $socket, mysqli_connect_errno(), mysqli_connect_error()); 21 } 22 23 if (!mysqli_query($link, 'DROP TABLE IF EXISTS test')) { 24 printf("Failed to drop old test table: [%d] %s\n", mysqli_errno($link), 25mysqli_error($link)); 26 } 27 28 if (!mysqli_query($link, 'CREATE TABLE test(id INT, label CHAR(1), PRIMARY 29KEY(id)) ENGINE=' . $engine . " DEFAULT CHARSET=gb2312")) { 30 printf("Failed to create test table: [%d] %s\n", mysqli_errno($link), 31mysqli_error($link)); 32 } 33 34 var_dump(mysqli_set_charset($link, "gb2312")); 35 36 if ('����\\\\����' !== ($tmp = mysqli_real_escape_string($link, '����\\����'))) 37 printf("[004] Expecting \\\\, got %s\n", $tmp); 38 39 if ('����\"����' !== ($tmp = mysqli_real_escape_string($link, '����"����'))) 40 printf("[005] Expecting \", got %s\n", $tmp); 41 42 if ("����\'����" !== ($tmp = mysqli_real_escape_string($link, "����'����"))) 43 printf("[006] Expecting ', got %s\n", $tmp); 44 45 if ("����\\n����" !== ($tmp = mysqli_real_escape_string($link, "����\n����"))) 46 printf("[007] Expecting \\n, got %s\n", $tmp); 47 48 if ("����\\r����" !== ($tmp = mysqli_real_escape_string($link, "����\r����"))) 49 printf("[008] Expecting \\r, got %s\n", $tmp); 50 51 if ("����\\0����" !== ($tmp = mysqli_real_escape_string($link, "����" . chr(0) . "����"))) 52 printf("[009] Expecting %s, got %s\n", "����\\0����", $tmp); 53 54 var_dump(mysqli_query($link, "INSERT INTO test(id, label) VALUES (100, '��')")); 55 56 mysqli_close($link); 57 print "done!"; 58?> 59--CLEAN-- 60<?php 61 require_once 'clean_table.inc'; 62?> 63--EXPECT-- 64bool(true) 65bool(true) 66done! 67