2012-04-11 56 views
0

有誰知道,刪除操作中是否有CRUD中的bug。 DB適配器:Zend_Db不刪除表格行

$this->_db = Zend_Registry::get("db"); 

我這樣做:

$sql = "DELETE FROM premium_items WHERE id = '$id'"; 
        $stmt = new Zend_Db_Statement_Pdo($this->_db, $sql); 
        return $stmt->execute(); 

$sql = "DELETE FROM premium_items WHERE id = ?"; 
       $stmt = new Zend_Db_Statement_Pdo($this->_db, $sql); 
       return $stmt->execute(array($id)); 

$this->_db->delete('premium_items', "id = '$id'"); 

每個變種工作沒有任何錯誤,但不會做什麼它必須這樣做。 在這種情況下我能做些什麼?

回答

1

隨着Zend_Db_Adapter,嘗試:

$this->_db->delete('premium_items', array("id = ?" => $id)); 

,或者在這種特殊情況下,你可以這樣做:

$this->_db->delete('premium_items', 'id = ' . (int)$id); 

(但只有當你使用一個整數做一個和你投它)

+0

找到了解決辦法,大家說的沒錯,一個剛剛總是要檢查事務被提交:( – 2012-04-11 10:33:06

1

在你的模型(Zend_Db_Table_Abstract):

$row = $this->find($id)->current(); 
$row->delete(); 

或者

$db = $this->getAdapter(); 
$db->delete($table, $db->quoteInto("id = ?", $id)); 
+0

其實,我本已: '公共職能__construct(Zend_Db_Table_Abstract $ DBTABLE,$ ID ) { \t $ this - > _ dbTable = $ dbTable; \t if($ id){ \t \t $ this - > _ row = $ this - > _ dbTable-> find($ id) - > current();其中{ \t} else { \t \t $ this - > _ row = $ this - > _ dbTable-> createRow(); \t} }' 然後 '公共函數刪除(){ \t返回$此 - > _按行>刪除(); }' – 2012-04-11 10:16:57

+0

我已經有這個問題,沒有找到zend_db_table函數的任何解決方案.. 我解決了這與我的最後一個代碼 – TeChn4K 2012-04-11 10:19:10