CakePHP 2.2 MSSQL / PDO Alternatives? - php

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.

Related

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.

How Do I Use ODBC in CakePHP 2?

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.

PHP Firebird API: php_interbase or PDO?

We've been using PDO for 2 years in new scripts to connect to our MySQL, PostgreSQL and SQLite databases.
We're now starting a project in which we'll need to read (and maybe a few simple UPDATE's) a Firebird 2.5 database file. I'd like to use PDO since we already use that and it will be less of a transition. However the PDO_FIREBIRD PECL package seems to be last updated in 2006.
So my question is: is it better to use the PDO Firebird driver or the php_interbase API for a new project? I.e. is the PDO Firebird driver production worthy?
The PDO Firebird is stable if you use it from main repository of PHP
You should use the the extension that comes with Php not the PECL one
Here is the PDO health status from last Year http://www.firebirdnews.org/?p=6619
Many bugs are fixed from then so you can just try it and abuse it.
The version from PECL is not updated for many years but i will take care of it soon https://bugs.php.net/bug.php?id=58824
Of course the php_ibase api is much older and well tested in production systems for years (from the old times of php3 ~ 1998)

Sqlserv extension on mac

My company uses the sqlserv extension to connect to a MSSQL database. This extension was chosen over the mssql extension because it is actively being maintained by Microsoft and the mssql driver is no longer maintained at all. My colleague has always worked in a windows enviroment so he could just download the proper DLL file and voila, sqlserv is available. Since i am running on Mac OSX 10.8.1 i don't share this luxery.
So basically the question is: does anyone know of a sqlserv php extension in the form of a .so file?
You cannot run the SQLSRV extension on anything other than Windows as stated here:
http://php.net/manual/en/sqlsrv.installation.php
However, even if you could, I would strongly urge you to stay away from the SQLSRV extension as it is extremely buggy and underdeveloped. You would be much better off using PDO!
I spent days trying to work out which extension to use, and after much research and questions on stackoverflow, it was clear that PDO was the only realistic solution for connecting to an MSSQL database. Not to mention the additional functionality that you have!
Try and execute stored procedures, return multiple recordsets along with output parameters using the SQLSERV extension!! Just one of the many features that can be done in a few lines with PDO but cannot be done with SQLSERV.
Furthermore, PDO is faster!

How to migrate from my WAMP environment to using MSSQL?

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.

Categories