Anyone who has worked much with the Zend framework much will be familiar with the framework’s reliance on config files. I recently worked on a project where I needed to set some database configurations in a Zend config file and it took me some time to figure out the correct syntax for them. My project uses the Oracle adapter, and the options I needed to set were for case folding (specifying the case of column names) and for auto quote identifiers (which controls applying identifier quoting automatically or not). The Zend documentation was pretty clear on how to set up these parameters if you are creating a database connection by creating an options array and passing it into the db factory method, but for my project I needed to set up these options in an ini file.
Here’s how you would add these configurations to the factory method options array:
$options = array( Zend_Db::AUTO_QUOTE_IDENTIFIERS => false Zend_Db::CASE_FOLDING => Zend_Db::CASE_UPPER; // or use Zend_Db::CASE_LOWER or Zend_Db::CASE_NATURAL );
It took me a bit of digging into the Zend_Db and Zend_Db_Adapter_Abstract classes to figure out how to translate the above into the correct syntax for the ini file. First of all, anything you want to add to the ‘options’ array needs to be preceded by ‘resources.db.params.options.’ After I had that, I found the correct name for each of the options and their values in Zend_Db. Here is how you would write the case folding option in a config file:
//natural case resources.db.params.options.caseFolding = 0 //lower case resources.db.params.options.caseFolding = 1 //upper case resources.db.params.options.caseFolding = 2
For the auto quote identifiers, what took me the most time to figure out (after the parameter name) was that even though I could write ‘false’ in the options array, the config file requires a ‘0’ for a false value (and 1 for a true value) in order for the option to be set correctly:
resources.db.params.options.autoQuoteIdentifiers = 0 resources.db.params.options.autoQuoteIdentifiers = 1
And additionally, here’s how you would write these out if you are using Multidb (as I was):
resources.db.multidb.db_default.autoQuoteIdentifiers = 0 resources.db.multidb.db_default.autoQuoteIdentifiers = 1
Hope this saves some of you time in your own projects. If you have any Zend DB config tips or tricks of your own, please share them in the comments!