pdo - Unicode characters not displayed properly with PHP and Vertica db -
summary
i'm trying query vertica database using php 7.0.9 , pdo via odbc connection, special characters such accented letters , euro symbol not displayed in generated html page.
according vertica docs:
all input data received database server expected in utf-8, , data output vertica in utf-8
environment setup
os centos linux release 7.2.1511 kernel 3.10.0-327.28.3.el7.x86_64
php 7.0.9 packages installed:
php70w-cli-7.0.9-1.w7.x86_64 php70w-7.0.9-1.w7.x86_64 php70w-pear-1.10.1-1.w7.noarch php70w-odbc-7.0.9-1.w7.x86_64 php70w-mbstring-7.0.9-1.w7.x86_64 php70w-common-7.0.9-1.w7.x86_64 php70w-process-7.0.9-1.w7.x86_64 php70w-xml-7.0.9-1.w7.x86_64 php70w-pecl-xdebug-2.4.0-1.w7.x86_64 php70w-pdo-7.0.9-1.w7.x86_64
additional packages:
unixodbc-2.3.1-11.el7.x86_64 vertica-client-7.2.3-0.x86_64
relevant configuration files:
/etc/vertica.ini
[driver] drivermanagerencoding=utf-16 odbcinstlib=/usr/lib64/libodbcinst.so errormessagespath=/opt/vertica loglevel=4 logpath=/tmp
/etc/odbcinst.ini
[hpvertica] description = vertica odbc driver driver = /opt/vertica/lib64/libverticaodbc.so [odbc] threading = 1
/etc/odbc.ini
[odbc data sources] test_vertica = "test vertica" [test_vertica] description = test vertica driver = hpvertica database = vmart servername = <redacted> uid = <redacted> pwd = <redacted> port = 5433
test case
if create table special characters , query it, results displayed correctly in terminal (environment variable $lang
set en_us.utf-8
):
# /opt/vertica/bin/vsql -h <redacted> -d vmart -u dbadmin vmart=> create table stackoverflow(str varchar(100)); vmart=> insert stackoverflow(str) values ('àèìòù €uro'); vmart=> commit; # /opt/vertica/bin/vsql -h <redacted> -d vmart -u dbadmin -c 'select * stackoverflow' str ------------ àèìòù €uro (1 row) # echo 'select * stackoverflow' | isql test_vertica sql> select * stackoverflow +-----------------------------------------------------------------------------------------------------+ | str | +-----------------------------------------------------------------------------------------------------+ | àèìòù €uro | +-----------------------------------------------------------------------------------------------------+ sqlrowcount returns 1 1 rows fetched
however, simple php script send garbage user agent:
<?php $dbconn = new pdo('odbc:test_vertica'); $sql = 'select * stackoverflow'; $statement = $dbconn->prepare($sql); $statement->execute(); $results = $statement->fetchall(pdo::fetch_assoc); header('content-type: text/html; charset=utf-8'); var_dump($results);
output in terminal:
# php /var/www/html/stackoverflow.php /var/www/html/stackoverflow.php:8: array(1) { [0] => array(1) { 'str' => string(17) "àèìòù €uro" } }
output in browser (also tried in latest chrome , ie):
# elinks -dump http://localhost/stackoverflow.php /var/www/html/stackoverflow.php:10: array (size=1) 0 => array (size=1) 'str' => string '..... .uro' (length=10)
it appears instead of special characters, "sub" ascii code (hex 1a) sent user agent. browser display dot, others space.
any ideas? thanks.
Comments
Post a Comment