Abstracting Oracle Connectivity with PHP/OCI8 - Page 5
November 25, 2002
How to Switch Between Development, QA and Production Environments
We created that OCI8Hook class with database login and password abstraction
for a reason. In many corporations, you'll have multiple environments. You'll
want to build your code against the development environment, test it on a QA
environment and finally, if all goes well, send it out to a production
environment. Well, that's one more advantage to having your connection strings
abstracted into the
To toggle between enviroments, simply change the connect string for your DBNAME.
Say I'm running all my queries against 'DBXYZ' with the following
to something like this:
Or if you wanted to be really fancy, you might consider sticking an IF statement in there like this:
The code I've shown you in this article may or may not work exactly from your cut-and-paste. However, I use this same structure for writing all the Oracle connectivity on my current projects...so I know it works. By abstracting the authentication to a single location, I can manage my application's connection strings much easier. By using the 'query' function for encapsulating all queries, I gain a significant speed up in application development time. It also helps to keep the code broken into distinct classes or 'objects'. When it comes time to hunting down problems and making enhancements, you'll be glad you abstracted the complicated portions of your PHP code so that you can concentrate on the true business logic.
Dante Lorenso, email@example.com