使用 PHP 插入 Unicode 字符 -> ODBC-> 微软SQL?

发布于 2024-07-30 08:09:33 字数 337 浏览 2 评论 0原文

我有以下代码:

$sql = "update tbl_test set category = N'resumé';

echo $sql;

$rs=odbc_exec($conn,$sql);

其中 $conn 是到 MSSQL Server 的 DSN ODBC 连接。 问题似乎是 PHP 和 MySQL(也许是 ODBC?)之间的某个 unicode 字符被转换为垃圾。 如果我将 echo 所显示的内容直接复制粘贴到企业管理器中,它就会很好地插入到 MS SQL 中。 但是,如果我运行代码,它总是作为 resumé 进入 MSSSQL 。 知道我在这里缺少什么吗?

I have the following code:

$sql = "update tbl_test set category = N'resumé';

echo $sql;

$rs=odbc_exec($conn,$sql);

Where $conn is a DSN ODBC connection to an MSSQL Server. The problem seems to be that somewhere between PHP and MySQL (Maybe ODBC?) unicode characters are converted to junk. If I copy paste exactly what the echo says directly into Enterprise Manager, it inserts into MS SQL fine. If I run the code however, it always goes into MSSSQL as resumé . Any idea what I'm missing here?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

最初的梦 2024-08-06 08:09:34

问题不是 ODBC,而是 PHP...解决方案是对从数据库返回的字符串使用 utf8_decode() 。

The problem was not ODBC, but PHP... solution was to use utf8_decode() on the strings returned from the database.

分分钟 2024-08-06 08:09:34

如果您在 Windows 上运行 PHP 5.3,使用 PDO_ODBC 和 SQL Native Client,并且您的输入文本是 UTF-8,那么这应该会自动工作。

If you are on Windows and running PHP 5.3, using PDO_ODBC with SQL Native Client, and your input text is UTF-8, this should just work automatically.

山人契 2024-08-06 08:09:34

我会小心翼翼地走在这里。 过去,在处理 SQL Server 和 PHP 集成时,我遇到过 SQL Server 使用 Unicode 字符实际所需存储空间 3 到 5 倍的情况。 取决于您连接到数据库的方式以及数据的编码方式。 我的理解是,MSFT 正在开发一个新的驱动程序(或者可能已经发布了一段时间)来解决该问题并总体上改进 PHP 集成。 对于一些较旧的堆栈,您可能会遇到麻烦。 我建议查看数据库中的数据大小,以验证连接是否未填充您的数据。

雅各布

I would tread carefully here. In the past, when dealing with SQL Server and PHP integration, I have encountered cases where SQL Server uses between 3 and 5 times as much storage space as is actually needed for Unicode characters. Depending on how you connect to the database and how the data is encoded. My understanding is that MSFT is working on a new driver (or it has possibly been out for a while) that addresses the issue and generally improves PHP integration. With some of the older stacks, you might run into trouble. I recommend looking at the data size in the DB to verify that the connection is not padding your data.

Jacob

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文