且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

php5 mssql utf-8问题

更新时间:2023-02-22 15:19:18

我今天正在解决这个问题(我测试了罗马尼亚语deutch和

俄语字符。

主要要求是:

1.你的文件必须是UTF-8 >
2.您的数据库表或列必须是UTF-8

3.在调用任何查询之前,您应该执行以下查询


SET NAMES''utf8''


这将在utf-8模式下设置为mysql的连接,如果它没有被

默认的MySql配置设置。

4.只需在表格中插入数据,然后就可以选择它了。


希望这会帮助。


PS我在PHP 5和Mysql 4.1上测试了所有这些东西,所以如果你的配置

不同抱歉。

I was fighting with this problem today(i tested romanian deutch and
russian characters).
The main requiremnts are:
1. Your document must be UTF-8
2. Your database table or column must be UTF-8
3. Before calling any queries you should execute the following query

SET NAMES ''utf8''

this will set conection to mysql in utf-8 mode if it wasn''t set by the
default MySql config.
4. Just Insert your data in the table and then you will be able to
select it.

Hope this will help.

P.S. I tested all this stuff on PHP 5 and Mysql 4.1 so if your config
is different sorry.


谢谢alex i will尝试明天做类似的事情..但是不是

真的很有希望,因为我使用的是microsoft sql server ..而且php和mssql之间的连接

似乎真的很不友好ot utf-8 :-(

thanks alex i will try to do something similar tomorrow.. but am not
really hopeful, because i use microsoft sql server.. and the connection
between php and mssql seems to be realy unfriendly ot utf-8 :-(


ralphie写道:
ralphie wrote:
嗨所有

自近2我与mssql和utf-8战斗,因为我需要存储和检索阿拉伯字符。

我尝试了com方法

http://groups.google.com/group/maili...1aa0bd48de23f0
我试过odbtp库,odbc和显然是mssql本地
扩展..但我是nev到目前为止,er成功地将utf-8数据存储在
mssql服务器(列类型nvarchar)中。如果有人有想法,或者认为他知道我可能做错了什么......这一切都非常受欢迎。

是的,内容类型被指定为在文档中跟随

< meta http-equiv =" content-type"含量=&QUOT; text / html的;字符集= UTF-8英寸/>

欢呼ralphie
hi all

since nearly 2 days i fight with mssql and utf-8 as i need to store and
retrieve arabic characters.

i tried the com approach

http://groups.google.com/group/maili...1aa0bd48de23f0

i tried as well the odbtp library, odbc and obviously the mssql native
extension.. but i never succeded so far to store utf-8 data in the
mssql server (column type nvarchar). if anybody has an idea, an
approach or thinks he knows what i might have done wrong.. it is all
highly appreciated.

ou yes the content type is specified as follows in the document

<meta http-equiv="content-type" content="text/html; charset=UTF-8" />

cheers ralphie




在工作中,我们还必须每天处理阿拉伯语脚本

我们也碰巧使用MSSQL。我发现使用nvarchar,ntext列类型没有好的

方式。也许在某个地方有一个

秘密旋钮。在任何情况下我都没有找到它。所以我们做的是

只将文本存储为常规varchar和text列中的UTF-8。


Varchar列有点问题,因为你冒险截断发生时将一个

字符切成两半。检索varchar列

宽于255使用扩展名也有些棘手(另外一方面是COM / $
,泄漏内存)。因此我们通常使用文本列

对文本长度没有自然限制。


当您将UTF-8字符串放入时,MSSQL有时会抱怨查询

,因为它并不认为你拥有的是有效文本。你需要做的只是CONVERT()或CAST()来强制它接受

字符串。



At work, we also have to deal with the Arabic script on a daily basis
and we also happen to use MSSQL. I have found is that there''s no good
way to make use of the nvarchar, ntext column type. Maybe there''s a
secret knob somewhere. I didn''t find it in any event. So what we do is
just store the text as UTF-8 in regular varchar and text columns.

Varchar columns are a bit problematic, since you risk chopping a
character in half when truncation happens. Retrieving varchar columns
wider than 255 is also somewhat tricky using the extension (COM on the
other hand, leaks memory). So we usually use a text column when there
is no natural limit on text length.

MSSQL will sometimes complain when you put a UTF-8 string into a query
because it doesn''t think that what you have is valid text. What you
have to do is just CONVERT() or CAST() to force it to accept the
string.