需要帮助,使用PHP ODBC驱动程序从Vertica查询UTF8字符串 [英] Need help querying UTF8 strings from Vertica with PHP ODBC driver

查看:189
本文介绍了需要帮助,使用PHP ODBC驱动程序从Vertica查询UTF8字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在想出最好的方法来处理PHP中的UTF8字符.我能够很好地将UTF8数据(中文字符)加载到Vertica中,并且在使用JDBC客户端时可以在其中看到它们,因此我知道数据记录正确.

I've been having some trouble figuring out the best way to handle UTF8 characters in PHP. I'm able to load UTF8 data (chinese characters) into Vertica just fine, and can see them there when using a JDBC client, so I know the data is being recorded correctly.

但是,当我通过PHP查询时,包含UTF8字符的字符串为空.但是,我可以执行类似将UTF8字段包装在URI_PERCENT_ENCODE函数中的操作,然后对PHP中的数据执行urldecode,以正确输出字符.

However, when I query via PHP, strings that contain UTF8 characters come through as nulls. However, I can do something like wrap the UTF8 field in a URI_PERCENT_ENCODE function, then do a urldecode on the data in PHP, which outputs the characters correctly.

是否有建议使用的ODBC驱动程序设置或PHP设置来更优雅地处理UTF8?

Are there any ODBC driver settings, or PHP settings that you can recommend to handle UTF8 more gracefully?

我们正在运行PHP 5.3(64位).

We are running PHP 5.3, 64 bits.

推荐答案

无论是什么,当使用Windows版Vertica 64位ODBC并调用SQLDescribeColW来描述具有中文名称和中文列名称的表时(例如,描述SQL语句,例如"select * from mytable"),返回的名称编码为"funky UTF-8".

For whatever it's worth, when working with the Vertica 64-bit ODBC for Windows and calling SQLDescribeColW to describe a table with Chinese name and Chinese column names (i.e. describing an SQL statement like 'select * from mytable'), the names returned encoded in "funky UTF-8".

笨拙的UTF-8"或FUTF-8编码使用wchar_t [](在Windows上,它是一个16位值的数组),其中在数组的每个条目中,只有一个真实的UTF-8字节

The "funky UTF-8" or FUTF-8 encoding uses wchar_t[] (on Windows it is an array of 16-bit values) where in each entry in the array, there is a single real-UTF-8 byte.

例如,如果列名称为时髦",其UTF-16编码为 65f6h,9ae6h (两个字符,每个16位),而其UTF-8编码为 e6h, 97h,b6h,e9h,abh,a6h (两个字符,每个3个字节),然后在FUTF-8中,您将得到: 00e6h,0097h,00b6h,00e9h,00abh,00a6h ( 6个字符,每个16位).

For example, if the column name was "时髦" whose UTF-16 encoding is 65f6h,9ae6h (two characters, 16 bits each) and its UTF-8 encoding is e6h, 97h, b6h, e9h, abh, a6h (two characters, 3 bytes each) then in FUTF-8 you'd get: 00e6h, 0097h, 00b6h, 00e9h, 00abh, 00a6h (6 characters, 16 bits each).

我想这就是PHP的空值.我将其称为ODBC驱动程序的错误.

I guess that this is what puts in null for PHP. I'd call it a bug of the ODBC driver.

这篇关于需要帮助,使用PHP ODBC驱动程序从Vertica查询UTF8字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆