我有以下sql查询,我需要在zend2中编写它。
DELETE FROM test_table WHERE user_id = 2 ORDER BY id ASC LIMIT 10
我试过这个:
$sql = new Sql($this->dbAdapter);
$delete = $sql->delete();
$delete->from('test_table');
$delete->where(array('user_id' => 4));
$delete->order('Id ASC');
$delete->limit(10);
$stmt = $sql->prepareStatementForSqlObject($delete);
$results = $stmt->execute();
但是当我添加这两行时它不起作用:
$delete->order('Id ASC');
$delete->limit(10);
答案 0 :(得分:0)
猜猜你正在使用SQL适配器。但是,如果您查看SQL ZF delete()
implementation,您会发现没有order()
或limit()
方法。所以你不能打电话给他们......
答案 1 :(得分:0)
您可以尝试以下操作:
$viewData = DB::table('tbl_contents')
->where('record_type', '=', 'Event')
->where('status', '=', 1)
->paginate(3);
return json_encode($viewData);
OR
$sql = new Sql($this->dbAdapter);
$delete = $sql->delete();
$delete->from('test_table');
$delete->where(array('user_id' => 4));
// get sql string
$deleteQuery = $sql->getSqlStringForSqlObject($delete);
// append the order by and limit
$deleteQuery .= " ORDER BY id ASC LIMIT 10";
// execute query
$result = $this->dbAdapter->query($deleteQuery, 'execute');