Zend Framework:把结果还给别人


Zend Framework: Give result back

我将返回MySQL查询的结果。但他返回了MySQL查询。

public function getLatestId() {
        $db = Zend_Db_Table::getDefaultAdapter();
        $db->getConnection();
        $result = $db->select()->from("raw_data", array(new Zend_Db_Expr("MAX(id) AS locationname")));
        return $result;
    }

$result具有选择查询语句,而不是获取结果所需的结果。 请尝试以下行:

$result = $db->select()->from("raw_data", array(new Zend_Db_Expr("MAX(id) AS locationname")));
$row = $this->fetchRow($result);
return $row->toArray();

我正在使用以下函数将最大 id 获取为最大项目编号

function getLatestId(){
    $select = $this->select()
        ->from('raw_data', array(new Zend_Db_Expr("MAX(id) AS maxItemNumber")));
    $row = $this->fetchRow($select);
    if(!$row){
        return 0;
    }
    $row = $rows->toArray();
    return $row['maxItemNumber'];
}
如果您想在插入

后立即获取最后一个插入ID,请使用返回和插入

return $this->insert($data);

这是因为您正在构建和下一个返回查询...但不执行此查询。哈里什·辛格(Harish Singh)展示了这一点。