我可以通过终端使用以下命令连接到MsSQL(远程PC):
TDSVER=8.0 tsql -H 192.168.1.10 -p 1433 -U Derrick -P Friday
我需要知道如何将成功的字符串翻译成PHP / PDO连接字符串,Ive尝试过:
$connect = new \PDO("dblib:host=192.168.1.10:1433", "Derrick", "Friday");
以及:
$connect = new \PDO("dblib:host=mssqlserver", "Derrick", "Friday");
配置文件中的“mssqlserver”是:
[mssqlserver]
host = 192.168.1.10
port = 1433
tds version = 8.0
我从PHP获得的错误是:
SQLSTATE[01002] Adaptive Server connection failed (severity 9)
TDS日志显示以下内容:
> log.c:194:Starting log file for FreeTDS 0.92.405 on 2014-04-14
> 18:25:21 with debug flags 0x4fff. net.c:204:Connecting to 192.168.1.10
> port 1433 (TDS version 5.0) net.c:270:tds_open_socket: connect(2)
> returned "Operation now in progress" net.c:310:tds_open_socket()
> succeeded util.c:159:Changed query state from DEAD to IDLE
> packet.c:133:Sending packet 0000 02 00 02 00 00 00 00 00-6d 69 6e 69
> 2e 6c 6f 63 |........ mini.loc| 0010 61 6c 00 00 00 00 00 00-00 00 00
> 00 00 00 00 00 |al...... ........| 0020 00 00 00 00 00 00 0a 44-65 72
> 72 69 63 6b 00 00 |.......D errick..| 0030 00 00 00 00 00 00 00 00-00
> 00 00 00 00 00 00 00 |........ ........| 0040 00 00 00 00 00 07 46
> 72-69 64 61 79 00 00 00 00 |......Fr iday....| 0050 00 00 00 00 00 00
> 00 00-00 00 00 00 00 00 00 00 |........ ........| 0060 00 00 00 00 06
> 31 38 36-34 00 00 00 00 00 00 00 |.....186 4.......| 0070 00 00 00 00
> 00 00 00 00-00 00 00 00 00 00 00 00 |........ ........| 0080 00 00 00
> 04 03 01 06 0a-09 01 00 00 00 00 00 00 |........ ........| 0090 00 00
> 00 00 50 48 50 20-66 72 65 65 74 64 73 00 |....PHP freetds.| 00a0 00
> 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 |........ ........| 00b0
> 00 00 0b 31 39 32 2e 31-36 38 2e 31 2e 31 30 3a |...192.1 68.1.10:|
> 00c0 31 34 33 33 00 00 00 00-00 00 00 00 00 00 00 00 |1433....
> ........| 00d0 00 11 00 06 46 72 69 64-61 79 00 00 00 00 00 00
> |....Frid ay......| 00e0 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00
> 00 |........ ........| 00f0 00 00 00 00 00 00 00 00-00 00 00 00 00 00
> 00 00 |........ ........| 0100 00 00 00 00 00 00 00 00-00 00 00 00 00
> 00 00 00 |........ ........| 0110 00 00 00 00 00 00 00 00-00 00 00 00
> 00 00 00 00 |........ ........| 0120 00 00 00 00 00 00 00 00-00 00 00
> 00 00 00 00 00 |........ ........| 0130 00 00 00 00 00 00 00 00-00 00
> 00 00 00 00 00 00 |........ ........| 0140 00 00 00 00 00 00 00 00-00
> 00 00 00 00 00 00 00 |........ ........| 0150 00 00 00 00 00 00 00
> 00-00 00 00 00 00 00 00 00 |........ ........| 0160 00 00 00 00 00 00
> 00 00-00 00 00 00 00 00 00 00 |........ ........| 0170 00 00 00 00 00
> 00 00 00-00 00 00 00 00 00 00 00 |........ ........| 0180 00 00 00 00
> 00 00 00 00-00 00 00 00 00 00 00 00 |........ ........| 0190 00 00 00
> 00 00 00 00 00-00 00 00 00 00 00 00 00 |........ ........| 01a0 00 00
> 00 00 00 00 00 00-00 00 00 00 00 00 00 00 |........ ........| 01b0 00
> 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 |........ ........| 01c0
> 00 00 00 00 00 00 00 00-00 00 00 00 00 00 00 00 |........ ........|
> 01d0 00 08 05 00 00 00 44 42-2d 4c 69 62 72 61 72 79 |......DB
> -Library| 01e0 0a 05 00 00 00 00 0d 11-75 73 5f 65 6e 67 6c 69 |........ us_engli| 01f0 73 68 00 00 00 00 00 00-00 00 00 00 00 00 00
> 00 |sh...... ........|
>
> packet.c:133:Sending packet 0000 02 01 00 61 00 00 00 00-00 00 00 00
> 00 00 0a 00 |...a.... ........| 0010 00 00 00 00 00 00 00 00-00 00 00
> 00 00 00 00 00 |........ ........| 0020 00 00 00 00 00 00 00 00-00 00
> 00 00 00 00 00 00 |........ ........| 0030 00 00 00 00 00 00 00 00-00
> 00 00 00 01 35 31 32 |........ .....512| 0040 00 00 00 03 00 00 00
> 00-e2 16 00 01 09 00 08 0f |........ ?.......| 0050 6d 7f ff ff ff fe
> 02 09-00 00 00 00 02 68 00 00 |m.????.. .....h..| 0060 00
> - |.|
>
> token.c:314:tds_process_login_tokens() util.c:159:Changed query state
> from IDLE to DEAD util.c:315:tdserror(0x7fec1968e950, 0x7fec196c8c60,
> 20017, 0) dblib.c:7874:dbperror(0x7fec196c8830, 20017, 0)
> dblib.c:7927:20017: "Unexpected EOF from the server"
> dblib.c:5737:dbgetuserdata(0x7fec196c8830) dblib.c:7948:"Unexpected
> EOF from the server", client returns 2 (INT_CANCEL)
> util.c:345:tdserror: client library returned TDS_INT_CANCEL(2)
> util.c:368:tdserror: returning TDS_INT_CANCEL(2) token.c:323:looking
> for login token, got 0() token.c:108:tds_process_default_tokens()
> marker is 0() token.c:111:leaving tds_process_default_tokens()
> connection dead login.c:459:login packet accepted
> util.c:315:tdserror(0x7fec1968e950, 0x7fec196c8c60, 20002, 0)
> dblib.c:7874:dbperror(0x7fec196c8830, 20002, 0) dblib.c:7927:20002:
> "Adaptive Server connection failed"
> dblib.c:5737:dbgetuserdata(0x7fec196c8830) dblib.c:7948:"Adaptive
> Server connection failed", client returns 2 (INT_CANCEL)
> util.c:345:tdserror: client library returned TDS_INT_CANCEL(2)
> util.c:368:tdserror: returning TDS_INT_CANCEL(2)
> dblib.c:1439:dbclose(0x7fec196c8830)
> dblib.c:253:dblib_del_connection(0x103a42d90, 0x7fec196c8c60)
> mem.c:598:tds_free_all_results() dblib.c:300:dblib_release_tds_ctx(1)
> dblib.c:5837:dbfreebuf(0x7fec196c8830)
> dblib.c:735:dbloginfree(0x7fec196c7b90) dblib.c:1508:dbexit(void)
> dblib.c:1508:dbexit(void) dblib.c:300:dblib_release_tds_ctx(1)
答案 0 :(得分:0)
$serverName = "IP\sqlexpress";
$connectionOptions = array("Database"=>"DB","UID"=>"name","PWD"=>"pass");
$conn2 = sqlsrv_connect( $serverName, $connectionOptions);