In this article Lorenzo explains a neat utility to simplify connecting to an Oracle database using PHP/OCI8. This is sure to make DB operations between PHP and Oracle much easier and faster.
Abstracting Oracle Connectivity with PHP/OCI8 - Switching Between Development, QA and Production Environments (Page 6 of 7 )
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 function getDBAuth($sid) { ... } function.
To toggle between environments, simple change the connect string for your DBNAME. Say I'm running all my queries against 'DBXYZ' with the following $stmt = $this->query("DBXYZ", $sql, $bargs);. Well, by simply changing the connect string from this:
case "DBXYZ": return (array("usernam1", "secret1", "DBXYZ")); To something like this:
case "DBXYZ": return (array("usernam1", "secret1", "TESTDB"));
Or if you wanted to be really fancy, you might consider sticking an IF statement in there like this:
case "DBXYZ": if (--I'm on the DEV environment--) { return (array("usernam1", "secret1", "DEVDB")); else if (--I'm on the QA environment--) { return (array("usernam1", "secret1", "TESTDB")); } else { return (array("usernam1", "secret1", "PRODDB")); } ...