Stored procs with Yii?
Posted 03 January 2011 - 02:25 PM
I'm working on an app that is releasing shortly, and I need a way to easily convert all my current Active Record queries over to MySQL stored procedures. I've never used stored procs before, but from what I have read it looks easy enough. The trouble is, I'm currently coding everything using Yii's AR (which is GREAT) but the stored procs are not done yet by our DBA. Is there an easy way (without breaking anything/doing much coding) to just override the "find" method for my models (and other methods)? I understand Yii does a bunch of DB stuff in the background, but I just need a way so I can implement stored procs WITHOUT re-coding all my find() calls and everything - I can do that, its fine, I'm just trying to find a way to limit coding because I need to get this thing working in a month.
Also, I'm assuming stored procs with yii are pretty simple? Something like User::model()->execute('stored proc') ?
What I was thinking of doing was this:
Change all my Models from extending Yii's Active Record, to extending my custom class which has its own "find" method (and other methods like "findAll") that just executes the stored proc in the DB. I'm assuming all my code will work correctly with little fuss this way? Will I have to also override "setAttributes" method or is this done automatically ? Keep in mind... in the production product we cannot be using active record, as my DBA is convinced otherwise (although if you can offer some convincing reasons why AR may be comparable to stored procs I might be able to convince them otherwise).
Posted 04 January 2011 - 03:47 AM
Maybe you will get some idea from them
Posted 04 January 2011 - 04:27 AM
@MichaelMackus: I had some very basic attempts of using stored procedures in Yii, but when connecting to Oracle DB. There shouldn't be much difference between it and MySQL. But these are only beginners attempts, so I can't actually paste any code example here right now. I'm in the same situation as you are right now, I'm waiting for my DBA to finish stored procedures to start using it. If I get to some interesting conclusions, I'll for sure post here.
Posted 04 January 2011 - 12:11 PM
@Trejder: Thanks, and I will definitely post my results as well. This is my first time working with Yii so I'm sure this will be interesting