Using PHP and Oracle database

I was working on bigger project using PHP (Yii) and Oracle database (through PDO and Yii). This isn't a very common combination and many developers thinks, that writing PHP application to use Oracle database is a pure madness, mostly due to many strange behaviors and nasty bugs, that are present in PDO driver for Oracle. I can actually confirm this. Following article contains links to my Yii forum discussions on various aspects of using Oracle with Yii and PHP. You may find it useful, if you're struggling with any problem.

If, for some reasons (as I do) you can't use good caching component and/or you're dealing with a large data sets (hundreds of thousands of records), then Active Record performance using Oracle is rather poor, in comparison to other RDBMSes. Though other may disagree, this is my feeling after around year of using Yii and Oracle.

OCI driver

I would not suggested using Oracle with PHP, unless you have additional time and money to spend on fighting with sometimes idiotic problems and errors. Notice, that this is not Yii problem, but PHP itself. Simply, take into consideration, that Oracle driver for PHP is after five or even more years still in experimental phase! Sounds like a joke, but unfortunately isn't a joke at all. And even it's own developers claims that using it in any production application is highly not recommended and that you're actually using it at your own risk!

In general, may have a lot of additional troubles, if you're developing application that uses different encoding than data encoding in your Oracle database. I was forced to do so, building UTF-8 application upon old Latin-1 encoded database. Horrible problems (exceptions on data columns exceeding their defined length) and all because of a stupid bug, reported more than a five years ago and not fixed until now, even though fixing it requires to change one line in pdo_oci.dll and recompile the library.

PDO

PDO isn't bad just because it has so incredibly bad OCI driver. I personally think that it is perfect and would be very disappointed if Yii2 would drop support on it. Yes, I agree that it has many errors, it hasn't been updated for a long, long time and is missing many important features of Oracle, but I wouldn't mix these facts with whole PDO. To be honest, I admire PDO that much, that if I would have to write a bigger project using PHP and Oracle I would consider hiring a C++ developer to write my own version of OCI driver for it.

Yes, I've heard that Oracle works fine with OCI8, is much more stable and provide more functions. But, as you pointed out correctly, it does not support PDO and therfore is not used in many famous frameworks that are build over PDO and are using it to get hands on all database stuff.

You can't (or at least shouldn't be) surprised of this situation. We may think different, but in general PHP is not recognized as good addition to Oracle. Simple because most people take Oracle as mature (maybe even most mature) RDBMS system while the same amount of people treats PHP like a toy for writing simple websites, not a professional coding language. Leaving Facebook (written almost entirely in PHP, and many more mature web apps) ahead, we must admit that an unbelievable mess in PHP and a very poor support for Oracle through PDO are the facts that supports this kind of thinking.

Conlusion

You may read some of my thoughts in these Yii Wiki articles:

  1. Using Yii with Oracle through PDO.
  2. Increasing AR performance in connections with Oracle.

And in these forum posts:

  1. CGridView (through PDO) is not able to fetch simple data set from Oracle DB.
  2. Oracle column names case-sensitivity.
  3. Forcing database charset when connecting to Oracle.

IT seems, that ricardograna is a quite talented Oracle and PHP developer. Look for his posts and wiki articles, if you need more information on these topics.

I've learnt a lot on working with Yii, PHP and Oracle and I'm quite satisfied. But, this was only possible, because I had a lot of time and was good paid for the project, that I've done. However, I'd think twice or even three times before getting myself into another PHP+Oracle project. Especially, if not good paid or in strict timeframes.

Leave a Reply