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