File: bug60616.phpt

package info (click to toggle)
php8.4 8.4.16-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 211,276 kB
  • sloc: ansic: 1,176,142; php: 35,419; sh: 11,964; cpp: 7,208; pascal: 4,951; javascript: 3,091; asm: 2,817; yacc: 2,411; makefile: 696; xml: 446; python: 301; awk: 148
file content (86 lines) | stat: -rw-r--r-- 2,484 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
--TEST--
odbc_exec(): Getting accurate unicode data from query
--EXTENSIONS--
odbc
mbstring
--SKIPIF--
<?php
include 'skipif.inc';
if ("unixODBC" != ODBC_TYPE) {
    die("skip ODBC_TYPE != unixODBC");
}

$conn = odbc_connect($dsn, $user, $pass);
$result = @odbc_exec($conn, "SELECT @@Version");
if ($result) {
    $array = odbc_fetch_array($result);
    $info = (string) reset($array);
    if (str_contains($info, "Microsoft SQL Server")) {
        echo "skip Doesn't work with MS SQL";
    }
}
?>
--FILE--
<?php

// Test strings
mb_internal_encoding("EUC_JP");
$euc_jp_base64 = 'pdal6aWkpcCl676uyqo=';
$euc_jp = base64_decode($euc_jp_base64);
$ascii = 'abcdefghijklmnopqrstuvwxyz;]=#0123456789';

include 'config.inc';
ini_set("odbc.defaultlrl", 4); // Set artificially low

$conn = odbc_connect($dsn, $user, $pass);

odbc_exec($conn, 'CREATE DATABASE bug60616Test ENCODING=\'EUC_JP\'');
odbc_exec($conn, 'USE bug60616Test');
odbc_exec($conn, 'CREATE TABLE bug60616 (ID INT, CHAR_COL CHAR(200), VARCHAR_COL VARCHAR(200), TEXT_COL TEXT)');
odbc_exec($conn, "INSERT INTO bug60616(ID, CHAR_COL, VARCHAR_COL, TEXT_COL) VALUES (1, '$euc_jp', '$euc_jp', '$euc_jp'), (2, '$ascii', '$ascii', '$ascii')");

$res = odbc_exec($conn, 'SELECT * FROM bug60616 ORDER BY ID ASC');

while(odbc_fetch_row($res)) {
    $char_col = odbc_result($res, "CHAR_COL");
    $varchar_col = odbc_result($res, "VARCHAR_COL");
    $id = odbc_result($res, "ID");
    $text_col = "";
    while (($chunk=odbc_result($res, "TEXT_COL")) !== false) {
        $text_col .= $chunk;
    }

    if ($id == 1) {
        $euc_jp_check = $euc_jp . str_repeat(" ", (200 - mb_strlen($euc_jp)));
        if (strcmp($char_col, $euc_jp_check) == 0 && strcmp($varchar_col, $euc_jp) == 0 &&
            strcmp($text_col, $euc_jp) == 0) {
            print "EUC-JP matched\n";
        } else {
            print "EUC-JP mismatched\n";
        }
    } else {
        $ascii_check = $ascii . str_repeat(" ", (200 - strlen($ascii)));
        if (strcmp($char_col, $ascii_check) == 0 && strcmp($varchar_col, $ascii) == 0 &&
            strcmp($text_col, $ascii) == 0) {
            print "ASCII matched\n";
        } else {
            print "ASCII mismatched\n";
        }
    }
}

?>
--CLEAN--
<?php
include 'config.inc';

$conn = odbc_connect($dsn, $user, $pass);

odbc_exec($conn, 'USE bug60616Test');
odbc_exec($conn, 'DROP TABLE bug60616');
odbc_exec($conn, 'DROP DATABASE bug60616Test');
?>
--EXPECT--
EUC-JP matched
ASCII matched