php串連sql server資料庫
來源:互聯網
上載者:User
安裝好php的sqlsrv模組
//本地串連
$serverName = "CX95DLISVW4C6TK\aaa";//電腦名稱\執行個體名
$connectionInfo = array("Database"=>"fff","ConnectionPooling"=>'','UID'=>'sa','PWD'=>'123');
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if( $conn == false)
{
echo "串連失敗!";
die( print_r( sqlsrv_errors(), true));
}else{
echo "dfdf";
$query=sqlsrv_query($conn,"select * from dbo.fdsf");
while($row = sqlsrv_fetch_array($query)){
print_r($row);
}
//print_r($query);
}
//遠端連線
$serverName = "192.168.1.5";
$connectionInfo = array("Database"=>"CIA","ConnectionPooling"=>'','UID'=>'sa','PWD'=>'360kad.com');
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if( $conn == false)
{
echo "串連失敗!";
die( print_r( sqlsrv_errors(), true));
}else{
echo "dfdf";
$query=sqlsrv_query($conn,"select * from CodeSiteTaker_Model");
while($row = sqlsrv_fetch_array($query)){
print_r($row);
}
//print_r($query);
}