facebook twitter hatena line email

Php/速度改善/zend framework

提供: 初心者エンジニアの簡易メモ
移動: 案内検索

Zend_Db_TableのfetchAllよりもZend_Db_Selectの方が速い

改善前

$adapter = (Zend_Db_Table)$this->getAdapter();
$where = array();
$where[] = $adapter->quoteInto("name like ?", "%".$name."%");
$all = $this->fetchAll($where, 'created desc');
if ($all) {
    $all = $all->toArray();
}
return $all;

改善後

$adapter = (Zend_Db_Table)$this->getAdapter();
$select = $adapter->select();
$select->from($this->_name, "*", $this->_schema);
$select->where("name like ?", "%".$name."%");
$select->order('created desc');
return $adapter->fetchAll($select);

php/zend_framework/DBモデル高速化 [ショートカット]

dbの$adapterのselectメソッドを使うよりも新規でselect()を作った方が速い

改善前

$select = $adapter->select();

改善後

$select = new Zend_Db_Select($this->_db);