Zend-Db 2.9 - SQL 带 RAND 顺序
Zend-Db 2.9 - SQL with RAND order
伙计们,我需要帮助,我正在使用 zend-db 2.9 - 我有一个 sql 需要 rand() 顺序,但是这个查询的结果是错误的
我的代码:
$sql = new Sql($this->dbAdapter);
$select = $sql->select(
['a'=>$this->table]
);
$select->order("RAND() ASC");
$select->limit(1);
$stt = $sql->prepareStatementForSqlObject($select);
$res = $stt->execute();
结果是:
SELECT `a`.* FROM `mytable` AS `a` ORDER BY `RAND``(``)` ASC LIMIT 1
如何解决?
我找到了答案:只需添加新表达式("RAND()")
$sql = new Sql($this->dbAdapter);
$select = $sql->select(
['a'=>$this->table]
);
$select->order([new Expression("RAND() ASC")]);
$select->limit(1);
$stt = $sql->prepareStatementForSqlObject($select);
$res = $stt->execute();
伙计们,我需要帮助,我正在使用 zend-db 2.9 - 我有一个 sql 需要 rand() 顺序,但是这个查询的结果是错误的 我的代码:
$sql = new Sql($this->dbAdapter);
$select = $sql->select(
['a'=>$this->table]
);
$select->order("RAND() ASC");
$select->limit(1);
$stt = $sql->prepareStatementForSqlObject($select);
$res = $stt->execute();
结果是:
SELECT `a`.* FROM `mytable` AS `a` ORDER BY `RAND``(``)` ASC LIMIT 1
如何解决?
我找到了答案:只需添加新表达式("RAND()")
$sql = new Sql($this->dbAdapter);
$select = $sql->select(
['a'=>$this->table]
);
$select->order([new Expression("RAND() ASC")]);
$select->limit(1);
$stt = $sql->prepareStatementForSqlObject($select);
$res = $stt->execute();