SQL Server 2005 and CakePHP

Posted on

Thought I would share the fruits of my labor from trying to get PHP, specifically CakePHP, to connect to a instance of SQL Server 2005 Express. From some initial searches, the only example I found specific to the CakePHP configuration in databases.php used ADOdb. I dowlnoaded the ADOdb library and placed it in the app/vendors directory. I was able to successfully connect to the database, however the SQL generate by CakePHP’s ADO class, had errors and would not probably prepend the field names with the table name.

Looking in CakePHP’s cake/lib/model/dbo, I saw what appeared to be a Microsoft SQL Server class. I was not initially able to connect using the class. With some further research, targeted at PHP’s mssql_pconnect, I found this MSDN article specifying what port to use and where to find that port in SQL Server Configuration Manager. All I had to do is add that port and now I am connecting and generating valid SQL statements. Below is an example configuration file.