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