write delete query for following in zend framework

纵然是瞬间 提交于 2019-12-24 08:37:22

问题


I am having a situation in my MySQL database table of row repeating
So I got this

DELETE from table1
USING table1, table1 as vtable
WHERE (NOT table1.ID=vtable.ID)
AND (table1.field_name=vtable.field_name)

Where table1 is the table and vtable is a virtual table

How should I write that in Zend Framework


回答1:


Zend_Db_Select supports the USING clause, but I think it's not supported by the Zend_Db_Adapter delete() method.

A possible alternative would be passing the SQL expression directly to the connection (if you are using the pdo_mysql adapter, it will be a PDO object):

$db->getConnection()->exec($sqlExpression);

(IMPORTANT: Make sure you quote properly all the identifiers and values in the SQL sentence, Zend_Db_Adapter has some extensive documentation about this).




回答2:


I'm not sure what you are trying to do, but this is how to use a basic delete in Zend:

$db->delete('table1', array('ID != ?' => $otherID, 'field_name = ?' => $otherFieldName));

Is this what you are looking for?



来源:https://stackoverflow.com/questions/7495113/write-delete-query-for-following-in-zend-framework

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!