简体   繁体   中英

Connect to a MS SQL database using PHP without Microsoft ODBC libraries

Microsoft has not released yet its library for Ubuntu 22.04 (msodbcsql18). So my PHP code does not work anymore:

$SERVER = "192.168.2.51";
$DATABASE = "DB_NAME";
$DRIVER = "/opt/microsoft/msodbcsql17/lib64/libmsodbcsql-17.9.so.1.1";
const USERNAME = "username";
const PASSWORD = "password";

$db = new PDO("odbc:driver=$DRIVER;server=$SERVER;database=$DATABASE", USERNAME, PASSWORD);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

it returns:

could not find driver

I wonder if there is an alternative method to connect to such a database that uses a different library. The DB is a SQL Server 19.

You can manually download and install the deb file from here .

It appears to be working for me so far, YMMV.

As an alternative we were previously using the old pdo_dblib driver with success.

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