开发者

Zend Framework Database Insert Issue

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


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);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜