2013-02-27 74 views
3

我需要使用PHP連接到遠程MSSQL服務器。我已經成功使用dblib連接,但它有一些相當「討厭」的限制。通過dblib使用MSSQL時PDO連接的替代方案

我發現它無法獲取ntext格式的列行,這裏有一個簡單的解決方法,但它限制了輸出(通過查詢將ntext轉換爲nvarchar),然後我注意到它也有以十進制格式獲取行的問題(或者看起來很不幸,一般錯誤4004對所有東西都會引起不太大的幫助)。

只是有太多的黑客需要,我喜歡,有沒有更好的方式來處理這一點,也許不同的DB庫,我應該看看我的連接?

值得一提的是,我用mssql_ *取得了巨大成功,但它顯然不是一個理想的做法,我希望用PDO保持。


值得注意的事情;

我Debian的運行,我知道微軟已經發布了ODBC驅動程序,但它們的驅動程序下載被竊聽,因此不工作(至少不能在非RHEL系統似乎)

+0

你可以發佈你的FreeTDS配置文件嗎? – 2013-02-27 15:40:30

+0

當然; http://pastebin.com/ATQSF3sg – Clorith 2013-02-27 16:13:44

+0

如果您將您的tds版本更改爲8.0,它是否有所作爲? 'tds version = 8.0' – 2013-02-27 16:33:15

回答

2

待辦事項不使用dblib/mssql:驅動程序。

如果您使用的是Windows,請使用sqlsrv: driver。 (您必須下載一些DLL--鏈接的說明)。

如果您使用unix,請使用PDO odbc: driver,最好是unixODBC的風格。在Debian和Ubuntu上,您可以使用簡單的apt-get install php5-odbc來獲得此驅動程序。

+0

我沒有這個驅動程序,根據我所知道的是Windows驅動程序,我應該提到我在Debian上。 – Clorith 2013-02-27 14:00:57

+0

呵呵,然後用ODBC。 – 2013-02-27 14:17:24

+0

我很喜歡,但微軟的ODBC驅動程序是我找到的唯一的,他們只是爲RHEL(試圖在debian上運行,沒有工作) – Clorith 2013-02-27 14:20:40

0

當我執行:

TDSDUMPCONFIG=stdout TDSDUMP=stdout tsql -S <name in TDS.conf> -U '<domain>\<username>' -p 1443 -P <password> 

我得到這個:

log.c:196:Starting log file for FreeTDS 0.91 
     on 2013-03-22 15:55:50 with debug flags 0x4fff. 
config.c:185:Getting connection information for [XXX]. 
config.c:189:Attempting to read conf files. 
config.c:354:... $FREETDSCONF not set. Trying $FREETDS/etc. 
config.c:367:... $FREETDS not set. Trying $HOME. 
config.c:293:Could not open '/home/hillb/.freetds.conf' ((.freetds.conf)). 
config.c:297:Found conf file '/etc/freetds/freetds.conf' (default). 
config.c:483:Looking for section global. 
config.c:540: Found section global. 
config.c:543:Got a match. 
config.c:565: text size = '64512' 
config.c:540: Found section egserver50. 
config.c:540: Found section egserver70. 
config.c:540: Found section XXX. 
config.c:554: Reached EOF 
config.c:483:Looking for section XXX. 
config.c:540: Found section global. 
config.c:540: Found section egserver50. 
config.c:540: Found section egserver70. 
config.c:540: Found section XXX. 
config.c:543:Got a match. 
config.c:565: host = 'XXX' 
config.c:595:Found host entry XXX. 
config.c:599:IP addr is xxx.xxx.xxx.xxx. 
config.c:565: port = '1433' 
config.c:565: tds version = '8.0' 
config.c:788:Setting tds version to 8.0 (0x701) from $TDSVER. 
config.c:554: Reached EOF 
config.c:301:Success: [XXX] defined in /etc/freetds/freetds.conf. 
config.c:714:Setting 'dump_file' to 'stdout' from $TDSDUMP. 
config.c:224:Final connection parameters: 
config.c:225:   server_name = XXX 
config.c:226:  server_host_name = XXX 
config.c:227:    ip_addr = xxx.xxx.xxx.xxx 
config.c:228:   instance_name = 
config.c:229:     port = 1433 
config.c:230:   major_version = 7 
config.c:231:   minor_version = 1 
config.c:232:    block_size = 0 
config.c:233:    language = us_english 
config.c:234:   server_charset = 
config.c:235:  connect_timeout = 0 
config.c:236:  client_host_name = x 
config.c:237:   client_charset = UTF-8 
config.c:238:    app_name = TSQL 
config.c:239:    user_name = <domain>\<username> 
config.c:242:    library = TDS-Library 
config.c:243:    bulk_copy = 0 
config.c:244:  suppress_language = 0 
config.c:245:   encrypt level = 0 
config.c:246:   query_timeout = 0 
config.c:249:    database = 
config.c:250:    dump_file = stdout 
config.c:251:   debug_flags = 0 
config.c:252:    text_size = 64512 
config.c:253:   broken_dates = 0 
config.c:254:  emul_little_endian = 0 
config.c:255:  server_realm_name = 
log.c:196:Starting log file for FreeTDS 0.91 
     on 2013-03-22 15:55:50 with debug flags 0x4fff. 
locale is "en_US.UTF-8" 
locale charset is "UTF-8" 
using default charset "UTF-8" 
iconv.c:330:tds_iconv_open(0x98cb9e8, UTF-8) 
iconv.c:187:local name for ISO-8859-1 is ISO-8859-1 
iconv.c:187:local name for UTF-8 is UTF-8 
iconv.c:187:local name for UCS-2LE is UCS-2LE 
iconv.c:187:local name for UCS-2BE is UCS-2BE 
iconv.c:349:setting up conversions for client charset "UTF-8" 
iconv.c:351:preparing iconv for "UTF-8" <-> "UCS-2LE" conversion 
iconv.c:391:preparing iconv for "ISO-8859-1" <-> "UCS-2LE" conversion 
iconv.c:394:tds_iconv_open: done 
net.c:205:Connecting to xxx.xxx.xxx.xxx port 1433 (TDS version 7.1) 
net.c:270:tds_open_socket: connect(2) returned "Operation now in progress" 
net.c:310:tds_open_socket() succeeded 
util.c:156:Changed query state from DEAD to IDLE 
net.c:741:Sending packet 

[十六進制轉儲刪節]

token.c:555:processing result tokens. marker is fd(DONE) 
token.c:2339:tds_process_end: more_results = 0 
       was_cancelled = 0 
       error = 0 
       done_count_valid = 0 
token.c:2355:tds_process_end() state set to TDS_IDLE 
util.c:156:Changed query state from READING to IDLE 
token.c:2370:    rows_affected = 0 
util.c:104:logic error: cannot change query state from IDLE to PENDING 
token.c:540:tds_process_tokens(0x98cb9e8, 0xbf82fb48, 0xbf82fb4c, 0x100) 
token.c:543:tds_process_tokens() state is COMPLETED 
locale is "en_US.UTF-8" 
locale charset is "UTF-8" 
using default charset "UTF-8" 

到底在找什麼?