简体   繁体   中英

Doctrine2: DBAL connection to Sql-Server

Connecting to MSSQL using Doctrine2 on Unix

Im currently developing a project which uses Doctrine2 with PHP on an Ubuntu Server (x64). It's required to fetch data from a MSSQL-Server which is running externally.

Problem

Doctrine2 doesn't support the pdo_dblib driver, neither there's a support for sqlsrv on unix-like machines ( sqlsrv is windows only). Being that given, it seems like Doctrine simply doesn't have a built-in support for MSSQL-Servers on unix-machines.

Solutions

These are solutions I tried without success.

1. Write own wrapper for pdo_dblib and integrate in doctrine's DBAL

I couldn't figure out how to write my own driver, platform and schema for doctrines DBAL neither found anything usefull in its docs or per google.

Actual Question

Is there any kind of support for MSSQL-Servers with Doctrine 2 without using Symfony or other third-party code ?

Your original solution is not actually that hard to achieve. I've run into this issue trying to connect to SQL Server using ODBC, which is one option for linux hosts, and the only change that I needed was in this file .

If you update that function and use a valid ODBC connection string instead, it will work just fine. Of course the Doctrine folks didn't make it easy by making that function private, so you'll either have to resort to editing your library or copy/pasting the entire SQL Server driver code.

That said, SQL Server support with ODBC is somewhat poor. For example, I've run into an issue where exceptions are thrown if you use bound parameters inside a subquery. Even though it works just fine with Microsoft's official driver which itself is based on ODBC. Go figure. If possible, copy your data to a more Linux friendly database and work with it there.

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