"fff","ConnectionPooling"=>'','UID'=>'sa','PWD ..."/> "fff","ConnectionPooling"=>'','UID'=>'sa','PWD ...">

首页  >  文章  >  后端开发  >  php连接sql server数据库

php连接sql server数据库

巴扎黑
巴扎黑原创
2016-11-22 10:51:222214浏览

安装好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); 
}


声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn