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.
Related
I've looked all over the web and cannot seem to find an answer for this one: I'm hoping to develop an app for my company using CakePHP 2. the problem is that the app will have to pull data from a Progress OpenEdge database. I've got the ODBC SQL driver for the database installed on the server but I cannot figure out how to add an ODBC datasource in CakePHP 2. Is this supported? If not (pretty stupid in my opinion, seeing as it was supported in 1.3), than what PHP framework would recommend that does support ODBC?
NOTE: While the ODBC driver can communicate SQL commands, you cannot communicate directly with the database using SQL, so it needs to be through the ODBC connection.
We have a CakePHP 1.3 application that we're in the process of upgrading to 2.2.3. One of the requirements of our app is to be able to query into an MSSQL database of a separate application to do some authentication and to pull user data out.
After two wasted days of researching and harassing our webhost to install the PHP / PDO / MSSQL lib (we already have PDO for MySQL, sqlite and sqlite 2) it's staring to seem pretty grim.
TL;DR: We need to find a way to do PDO MSSQL queries under Linux.
Begin Rant:
The thing that's driving me crazy is this: The CakePHP devs BROKE MSSQL compatibility for the sake of making all their DB wrappers with PDO. If you had a 1.3 app on a Linux server that was happily connecting to MSSQL databases and want to upgrade it to 2.2, you will no longer be able to connect to that database because apparently using PDO is more important than ensuring that you don't destroy existing functionality for your users.
CakePHP 2.x Docs do NOT warn users of this pitfall, all they say is that you need PDO.
There should be a notice that PDO/MSSQL does not work under Linux, or there should be an alterantive to the Sqlserver.php datasource that's provided with stock CakePHP so that people upgrading their apps have a chance of getting their applications functional again under 2.2x
I am really steamed about this right now because I wasted a week of time porting things over from 1.3 to 2.2 and now it looks like I either have to manually write the queries and ignore CakePHP's great database abstraction, or I need to convert all my work BACK to 1.3 and give up all the new improvements in the latest version of CakePHP.
The trick is :
sudo apt-get install php5-sybase
For some reason extension is not called mssql
sybase worked fine for me
What you need to do is install the ODBC drivers from Microsoft and set up the odbc connection strings. The process can be a bit tricky but it does work, and the driver is stable.
You can then use $dbh = new PDO("odbc:CONNECTIONNAME", $user, $password); to connect through PDO.
Once that is sorted, I think you can still use the MSSQL data source but modifying the connection string.
I am debating between using MsSQL and SQLSrv to connect to SQL Server.
Our platform is running IIS7 on Windows and using PHP. We tried using the MsSQL extension to work but had problems so we decided to use SQLSrv instead since it was easier to get working.
Using MsSQL would be the preferred option because it fits the workflow better and the function names are similar to the ones used in SQL. Is it worth the effort to use MsSQL with PHP in light of the problems we are facing or should we use SQLSrv with the downsides mentioned.
Also, on the MSDN Docs for SQLSrv it mentions that the documentation is for preview and might change. Does that mean the functions could end up changing?
As far as the notice on the documentation all it means is they may change the wording of the document later in its release, I can't promise that the functions will stay the same however nothing on that page leads me to believe otherwise. Here is a Microsoft Wiki article on Accessing SQL Server Databases from PHP is says that the process outlined on that page is compatible with SQL Server 2005, SQL Server 2008, and SQL Server 2008 R2 so the software should not change since it needs to maintain compatibility with older versions of SQL Server.
You may also want to reference that wiki article, it contains step by step setup procedures for MsSQL and SQLSrv which may work for you and fix the issue you have.
I want to connect to a SQL Server 2000 from PHP installed in a unix platform (CentOs) and to be able to run queries (SELECT and UPDATE). The solution must support UTF-8 data.
As search through the web, I find out that there exists many different approaches (freeTDS, unixODBC, ODBTP, Easysoft ODBC, Easysoft ODBC-ODBC Bridge, PDO).
Could someone point me to the best solution for the specific connection?
PDO is the preferred library a.t.m, with PDO_DBLIB (at least, for Linux), see here. if you need it portable between Linux & Windows, use PDO_ODBC.
The fact that PDO_DBLIB was (and still is) experimental discourage me from using it. I decided to start testing a solution using freeTDS, that seemed to be the simpliest method. It turned out to function excellent, for that specific connection's case and I implemented the final application using it.
I have on my local PC installed WAMP environment (using WampServer OS).
Now I would need to change one script from working with MySQL to MSSQL.
I have no idea at all how to proceed, where to download MSSQL, how to install it and how to connect with PHP?
Thank you very much
Download mssql express http://www.microsoft.com/Sqlserver/2005/en/us/express.aspx
Familiarize yourself with one of the great database abstraction layers, for example PDO http://www.php.net/pdo
Refactor your code to use the database abstraction layer
You may need to rewrite the mysql specific things to "standard" SQL
Start by getting Sql Server working. If you are using an old copy of Sql Server (pre 2005) you will need to make sure ntwdblib.dll is present in your System32 directory, and removed from your PHP dll directory (ntwdblib.dll is installed with the enterprise tools, so you may have to install them on your PHP box as well). Once you have Mssql querying properly, start finding where Mssql differs from MySql in your code.
A couple of tips:
The ntwdblib doesn't accept long strings (I think it is limited to 4k, but don't quote me on that). You have to use Stored Procs if you are trying to process a string longer than 4k.
Try to use Sql Server 2005 if you can (see above), the ntwdblib.dll is ancient and has numerous issues.
The PHP site is your friend for mssql.