1
我有一個SQL Server表:希臘字符插入相比,SQL Server Management Studio中
create table tmp (fname nvarchar(40))
我有一個PHP腳本插入一些希臘字符:
$cn = sqlsrv_connect(...
// insert greek chars
sqlsrv_query($cn, "INSERT INTO tmp (fname) VALUES (N'ΚΩΝΣΤΑΝΤΙΝΟΣ')");
// read them back again
$rs = sqlsrv_query($cn, "SELECT fname FROM tmp");
$row = sqlsrv_fetch_array($rs, SQLSRV_FETCH_NUMERIC);
// output result
print "<br />from database: " . $row[0];
sqlsrv_close($cn);
可正常工作(即在希臘 - 希臘退出)
如果我現在使用SQL Server Management Studio中(SSMS):
select * from tmp
我得到:
ΚΩÎΣΤΑÎΤΙÎΟΣ
如果我使用SSMS插入:
delete from tmp
INSERT INTO tmp (fname) VALUES (N'ΚΩΝΣΤΑΝΤΙΝΟΣ')
select * from tmp
我得到:
ΚΩΝΣΤΑΝΤΙΝΟΣ
,但如果我訪問從PHP:
$cn = sqlsrv_connect(...
$rs = sqlsrv_query($cn, "SELECT fname FROM tmp");
$row = sqlsrv_fetch_array($rs, SQLSRV_FETCH_NUMERIC);
print "<br />from database: " . $row[0];
sqlsrv_close($cn);
我得到:
?O?S???????S
我試圖<meta charset="utf-8">
和<meta charset="utf-16">
- 沒有什麼區別。
所以 - 兩個問題:
這到底是怎麼回事?
我該如何獲得SSMS和php的一致性?
我使用:
Microsoft SQL Server 2012 (SP1) - 11.0.3000.0 (X64)
Oct 19 2012 13:38:57
Copyright (c) Microsoft Corporation
Standard Edition (64-bit) on Windows NT 6.1 <X64> (Build 7601: Service Pack 1) (Hypervisor)
Microsoft SQL Server Management Studio 11.0.2100.60
PHP 5.6.7
請點擊這裏:http://www.webr2.com/php-sql-server-how-to-set-charset-for-connection/ –