PHP connects to sql server database

巴扎黑
Release: 2016-11-22 10:51:22
Original
2212 people have browsed it

Install the sqlsrv module of php
//Local connection
$serverName = "CX95DLISVW4C6TKaaa";//Computer name instance name
$connectionInfo = array("Database"=>"fff","ConnectionPooling"=>'' ,'UID'=>'sa','PWD'=>'123');
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if( $conn == false)
{
echo "Connect Failed! ";
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);
}

//Remote connection
$serverName = "192.168.1.5";
$connectionInfo = array ("Database"=>"CIA","ConnectionPooling"=>'','UID'=>'sa','PWD'=>'360kad.com');
$conn = sqlsrv_connect( $ serverName, $connectionInfo);
if( $conn == false)
{
echo "Connection failed!";
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);
}


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!