Home > Backend Development > PHP7 > body text

How to connect to sql server in PHP7?

coldplay.xixi
Release: 2023-02-17 16:38:02
forward
4952 people have browsed it


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("");  
} 	
?>
Copy after login

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!

Related labels:
source:csdn.net
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