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