The easiest way (aka the way using the smallest amount of code) to insert a row into a database table using Zend_Db
is:
$data = array(
'created_on' => '2007-03-22',
'bug_description' => 'Something wrong',
'bug_status' => 'NEW'
);
$db->insert('bugs', $data);
The above code will insert a new row into the bugs
table whereas $db
is the Zend_Db_Adapter_Abstract
-subclass you created with Zend_Db::factory()
. Please see Writing Changes to the Database in the Zend Framework manual for more details and the whole spectrum of features Zend_Db
provides.
For the sake of completeness, the above code will issue a query to the database similar to:
INSERT INTO bugs (created_on, bug_description, bug_status)
VALUES ('2007-03-22', 'Something wrong', 'NEW')
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 fields created_on
, bug_description
and bug_status
and provided that you have the right filters and validators in place, adding a new row with values given in the form is as easy as
if ($form->isValid($_POST)) {
$db->insert('bugs', $form->getValues());
}
Storing a custom object is also very easy:
// $bug is your custom object representing a bug
$db->insert('bugs', array(
'created_on' => $bug->getCreatedOn(),
'bug_description' => $bug->getDescription(),
'bug_status' => $bug->getStatus()
));