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