1--TEST-- 2odbc_exec(): Getting accurate unicode data from query 3--SKIPIF-- 4<?php include 'skipif.inc'; ?> 5--FILE-- 6<?php 7 8// Test strings 9mb_internal_encoding("EUC_JP"); 10$euc_jp_base64 = 'pdal6aWkpcCl676uyqo='; 11$euc_jp = base64_decode($euc_jp_base64); 12$ascii = 'abcdefghijklmnopqrstuvwxyz;]=#0123456789'; 13 14include 'config.inc'; 15ini_set("odbc.defaultlrl", 4); // Set artifically low 16 17$conn = odbc_connect($dsn, $user, $pass); 18 19odbc_exec($conn, 'CREATE DATABASE odbcTEST ENCODING=\'EUC_JP\''); 20 21odbc_exec($conn, 'CREATE TABLE FOO (ID INT, CHAR_COL CHAR(200), VARCHAR_COL VARCHAR(200), TEXT_COL TEXT)'); 22 23odbc_exec($conn, "INSERT INTO FOO(ID, CHAR_COL, VARCHAR_COL, TEXT_COL) VALUES (1, '$euc_jp', '$euc_jp', '$euc_jp')"); 24odbc_exec($conn, "INSERT INTO FOO(ID, CHAR_COL, VARCHAR_COL, TEXT_COL) VALUES (2, '$ascii', '$ascii', '$ascii')"); 25 26$res = odbc_exec($conn, 'SELECT * FROM FOO ORDER BY ID ASC'); 27 28while(odbc_fetch_row($res)) { 29 $char_col = odbc_result($res, "CHAR_COL"); 30 $varchar_col = odbc_result($res, "VARCHAR_COL"); 31 $id = odbc_result($res, "ID"); 32 $text_col = ""; 33 while (($chunk=odbc_result($res, "TEXT_COL")) !== false) { 34 $text_col .= $chunk; 35 } 36 37 if ($id == 1) { 38 $euc_jp_check = $euc_jp . str_repeat(" ", (200 - mb_strlen($euc_jp))); 39 if (strcmp($char_col, $euc_jp_check) == 0 && strcmp($varchar_col, $euc_jp) == 0 && 40 strcmp($text_col, $euc_jp) == 0) { 41 print "EUC-JP matched\n"; 42 } else { 43 print "EUC-JP mismatched\n"; 44 } 45 } else { 46 $ascii_check = $ascii . str_repeat(" ", (200 - strlen($ascii))); 47 if (strcmp($char_col, $ascii_check) == 0 && strcmp($varchar_col, $ascii) == 0 && 48 strcmp($text_col, $ascii) == 0) { 49 print "ASCII matched\n"; 50 } else { 51 print "ASCII mismatched\n"; 52 } 53 } 54} 55 56?> 57--EXPECT-- 58EUC-JP matched 59ASCII matched 60--CLEAN-- 61<?php 62include 'config.inc'; 63 64$conn = odbc_connect($dsn, $user, $pass); 65 66odbc_exec($conn, 'DROP TABLE FOO'); 67odbc_exec($conn, 'DROP DATABASE odbcTEST'); 68 69?> 70