Home >Backend Development >PHP7 >How to connect to sql server in PHP7?

How to connect to sql server in PHP7?

coldplay.xixi
coldplay.xixiforward
2020-06-28 16:10:394978browse


How to connect to sql server in PHP7?

The latest version on the official website is 7.1.3, but this version is inconsistent with the Microsoft PHP SQL driver, resulting in the inability to load the php_sqlsrv_7_ts_x64.dll file. At first I thought it was the 32 and 64 versions that were wrong, but it still didn’t work after changing. Then I tried lowering the version and it worked, as shown below:



Connection code:

<?php
$Server="192.168.1.20";
$database="Test";
$uid="sa";
$pwd="123456";
$conInfo=array(&#39;Database&#39;=>$database,'UID'=>$uid,'PWD'=>$pwd);  
$link=sqlsrv_connect($Server,$conInfo);   
  
if( $link ){  
   
}  
else{  
    print_r( sqlsrv_errors(), true);  
   if( ($errors = sqlsrv_errors() ) != null) {  
        foreach( $errors as $error ) {  
            echo "SQLSTATE: ".$error[ 'SQLSTATE']."<br />";  
            echo "code: ".$error[ 'code']."<br />";  
            echo "message: ".$error[ 'message']."<br />";  
        }  
    }  
    die("");  
} 	
?>

Related learning recommendations: PHP Programming from beginner to master

The above is the detailed content of How to connect to sql server in PHP7?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:csdn.net. If there is any infringement, please contact admin@php.cn delete