简体   繁体   中英

How to connect to sql server from php (other computer)

I have a computer install sql server 2005
And other computer install xampp v3.2.1
i try to connect to sql server 2005 by php in computer install xampp but not working.

i download driver 3.0 for php from http://www.microsoft.com/en-us/download/details.aspx?id=20098

and i copy 2 file php_sqlsrv_54_ts.dll and php_pdo_sqlsrv_54_ts.dll to Xampp\\php\\ext
and i add code below to php.ini

[sqlsrv]
sqlsrv.LogSubsystems=-1
sqlsrv.LogSeverity=-1
sqlsrv.WarningsReturnAsErrors=0
extension=php_sqlsrv_54_ts.dll
extension=php_pdo_sqlsrv_54_ts.dll

i test connection by

$serverName = "nameserver";
$connectionInfo = array("Database"=>"namedatabase");
$conn = sqlsrv_connect($serverName, $connectionInfo);

if ($conn) {
    echo "success";
}else {
    die (print_r(sqlsrv_errors(),true));
}

but i get error

Array ( [0] => Array ( [0] => IMSSP [SQLSTATE] => IMSSP [1] => -49 [code] => -49 [2] => This extension requires the Microsoft SQL Server 2012 Native Client. Access the following URL to download the Microsoft SQL Server 2012 Native Client ODBC driver for x86: http://go.microsoft.com/fwlink/?LinkId=163712 [message] => This extension requires the Microsoft SQL Server 2012 Native Client. Access the following URL to download the Microsoft SQL Server 2012 Native Client ODBC driver for x86: http://go.microsoft.com/fwlink/?LinkId=163712 ) [1] => Array ( [0] => IM002 [SQLSTATE] => IM002 [1] => 0 [code] => 0 [2] => [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified [message] => [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified ) ) 

How to connect to sql server from php. Thanks

Check your error message where it says "This extension requires the Microsoft SQL Server 2012 Native Client." The client is an extra piece of software you install and you can get installer you download from Microsoft.

I'm not sure if this will work on SQL Server 2005 though?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM