1

I'm starting out using the Zend Framework and have created a suitable model which saves data back to a database table. The issue I am having is that the sql statement is trying to insert '?' as the value for each column in the database. I have created the following save function which passes an array of data to the DBtable adapter functions:

public function save()     {
    $data = $this->getData();
    if ($data['pageId']==0) {
        $this->getDbTable()->insert($data);
    } else {
         $this->getDbTable()->update($data, array('pageId = ?' => $data['pageId']));
    }
} 

This seems to go through the appropriate motions but the item is not added to the database and the sql statement within MySql logs looks something like:

insert into DB_Table ('pageId','title','body') values ('?', '?', '?');

Not quite sure where this is falling down, any pointers would be gratefully received.

Thanks

1 Answer 1

5

Data should be in next format:

$data = array(
   'pageId' => 1,
   'title'  => 'title',
   'body'   => 'body'
);

Are you sure that $this->getDbTable() returns your db adapter? Try to use:

$db = new Zend_Db_Table('table_name');
$db->insert($data);
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, bit of a "doh" moment with the getDbTable(). Thanks for your tip.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.