2013-02-11 66 views
0

我想在Abstract.php或模型中的Zend Framework中创建一个sql查询?但我很难弄清楚如何去做。我是zend框架中的新成员。Zend Framework创建一个sql函数

,我想创建这样看起来查询:

delete from users where id not in(select * from(select min(n.id)from users n group by n.email)x); 

但在Zend公司:

$results = $db->query('delete 
       from users 
       where id not in(
        select * from(
         min(n.id) 
         from users n 
         group by n.email 
       )x)'); 

看起来像$ DB有一个不确定的变量,什么样的数据库功能应该的数据库调用?我的数据库是在你写这个了Syntex执行您的自定义查询的application.ini

+1

这还没有半点有效的PHP代码。请参阅http://stackoverflow.com/a/5380654/1902010,了解与您尝试执行的操作相似的内容。 – ceejayoz 2013-02-11 21:53:14

+0

噢,谢谢你,但我怎样称之为删除 – 2013-02-11 22:07:10

+0

我想你可以将'select()'改为'delete()',但是你想在学习PHP之前先阅读文档,然后再进行破坏性更改这样的数据。 – ceejayoz 2013-02-11 22:08:55

回答

2

通话..

$db->getAdapter()->query('delete 
       from users 
       where id not in(
        select * from(
         min(n.id) 
         from users n 
         group by n.email 
       )x)');