Configuring SQL Server connection with ODBC driver in Zend Framework
Many Web Developers who work with websites or systems development use MySQL or PostgreSQL as their database, and in a project I developed, it was no different - I opted for MySQL.
However, during the project, the need arose to switch to using SQL Server. That’s when I was delighted to take advantage of the facilities that an ORM provides in terms of abstraction, in this case, I was using Doctrine 1.
But who said it was easy or quick? Although it’s simple, it took me a little while to figure out the “tricks” of configuring the DSN connection for SQL Server, and in this post, I’ll share the tips for those of you who need to perform this task.
Together with Doctrine 1, Zend Framework was used in the project, so the configuration of the database connection data was in the application.ini file of the application. In this file, the DSN configuration for MySQL looks like this:
To configure SQL Server here, the syntax is a little different. In this case, I used the ODBC driver for the connection:
Is that all? NO, there’s still the part of Doctrine initialization, which was defined in the Bootstrap file of the application. Let’s see the example for MySQL:
Until here, you should already be familiar, right? This works perfectly with MySQL. However, for SQL Server, you need to make an adjustment on line 13 since we need to pass the DSN connection in an array:
Simple, right?
With these tips above, you can now run your application on SQL Server.
For any tips and/or suggestions, please leave your comments.