<?php$serverName = "serverName\sqlexpress"; //serverName\instanceName
// Since UID and PWD are not specified in the $connectionInfo array,
// The connection will be attempted using Windows Authentication.$connectionInfo = array( "Database"=>"dbName");$conn = sqlsrv_connect( $serverName, $connectionInfo);if( $conn ) { echo "Connection established.<br />";
}else{ echo "Connection could not be established.<br />"; die( print_r( sqlsrv_errors(), true));
}為啥連接只需要提供服務器名字就可以,連接本機的和內網或者外網的服務器都是這樣嗎?給個名字就能找到要連的原理是啥?
1 回答

楊__羊羊
TA貢獻1943條經驗 獲得超7個贊
通過serverName
可以找到對應的IP,如果是本機可以不用服務器名,直接用.
。通過sqlexpress
可以知道SQL Server實例名稱。本機使用Windows集成驗證(Integrated Security=true
)可以不用用戶名/密碼,如果連接遠程的服務器就需要用戶名與密碼。
- 1 回答
- 0 關注
- 593 瀏覽
添加回答
舉報
0/150
提交
取消