So I just spent the past half hour reading and sorting through documentation on Zend_Db, Zend_Config and Zend_Config_Ini so that I could set my driver options in my config file.
I could’ve set the options in the bootstrap but figured there had to be a way to set things up in my ini file. After all, what would the point of an ini file be if you can’t set your configuration options in them?
The key to my issue ended up being Zend_Db. The bootstrap (if you followed the quickstart like i did) uses Zend_Db::factory() to set up your database connection. It does this by loading the configuration ini that you made. What the quickstart fails to mention is how to decipher your ini file. Or maybe it’s some kind of Zend right of passage to figure out how to go beyond setting up your environemnt host/dbname/username/password. Or maybe I’m just incredibly dumb. I’m more prone to believing the latter.
So for the sake of anyone else like me that possesses the curiousity to know why things work the way they do but don’t possess the patience to root documentation while doing a quickstart, here is a brief “wft is going on here”.
gives us a database adapter. It does this by parsing a Zend_Config object. If you’re using an ini, then Zend_Config_Ini parses your ini file by replacing creating arrays by (to extremely simplify) exploding the dots (.). So
becomes equivalent to
=array( "adapter"=>"PDO_MySQL", "params"=>array( "host"=>"localhost", "dbname"=>"kittens" ) )
Sidenote: I found that if you have a password that contains non-alphanumeric values, it’s best to encapsulate them in double-quotes. (i.e. database.params.password=”kittens!”) otherwise it cause Zend to hate you (short version of the outcome).
This basic understanding on how the ini file is parsed lead me to being able to do all sorts of fun stuff. In particular, was setting the driver options.
At first I thought I could do something like database.driver_options or database.driver.options to set things up. It made sense to me since the adapter is set outside of the connection parameters. What I eventually discovered was that according to Zend_Db, the params key isn’t limited to the connection. It also encompasses the driver settings. So in order to set my PDO driver settings to the way I want them to be, I ended up doing:
database.params.driver_options.PDO::ATTR_PERSISTENT=true database.params.driver_options.PDO::ATTR_ERRMODE=PDO::ERRMODE_EXCEPTION database.params.driver_options.PDO::MYSQL_ATTR_USE_BUFFERED_QUERY=true database.params.driver_options.PDO::ATTR_DEFAULT_FETCH_MODE=PDO::FETCH_ASSOC
I think I’m going to have a lot of fun with my config ini in the future.