I want to save an object or form to the database. Only I can’t find the easiest (or normal) way for how to do this.
I found a lot of tutorials, but none seem to be easy or current. Can someone please help me with this?
I use version 1.9.3 of the Zend Framework.
The easiest way (aka the way using the smallest amount of code) to insert a row into a database table using
Zend_Dbis:The above code will insert a new row into the
bugstable whereas$dbis theZend_Db_Adapter_Abstract-subclass you created withZend_Db::factory(). Please see Writing Changes to the Database in the Zend Framework manual for more details and the whole spectrum of featuresZend_Dbprovides.For the sake of completeness, the above code will issue a query to the database similar to:
The next step would be a more sophisticated approach using
Zend_Db_Table.EDIT:
Given that you have a
Zend_Form($form) with the appropriate fieldscreated_on,bug_descriptionandbug_statusand provided that you have the right filters and validators in place, adding a new row with values given in the form is as easy asStoring a custom object is also very easy: