简体   繁体   中英

Connection from Linux server to a windows server with a SQL Server DB

I want to connect from my Linux web server to a SQL Server DB running on a windows server. I have all the right extensions on the Linux box (near as I can tell) and am trying to connect with the following code:

<?php

$server = "ip address";
$user = "userName";
$password = "passWord";
$database = "dataBase";

// Connect to MS SQL database.

$conn = odbc_connect("Driver={SQL Server Native Client 10.0};Server=$server;Database=$database;", $user, $password);

If ($conn) {
    echo "Database connection is established.<br />\n";
} 
else {
    echo "Connection could not be established.<br />\n";
    die ( print_r(odbc_errormsg(), true));
}
?>

I get this error:

Connection could not be established. [unixODBC][Driver Manager]Can't open lib 'SQL Server Native Client 11.0' : file not found

I assume that this issue is on the windows machine? I have never made this type of connection before.

What I want to be able to do is connect to this DB from my Linux web server to manipulate the data within that database. (add, edit, delete)

The SQL Server Native Client ODBC driver is only for Windows. On Linux, install Microsoft ODBC Driver 17 for SQL Server (latest version as of this writing). Then specify "Driver={ODBC Driver 17 for SQL Server}" in the connection string.

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