protected function _find($multiple, $key = null, $value = null) { $query = \DB::find($this->_criteria); $start_time = microtime(true); $result = $query->execute($this->_database_instance); if (static::$profiling) { $sql = (string) $query; $time_delta = sprintf('%.3F', microtime(true) - $start_time); file_put_contents(APPPATH . 'logs/ActiveRecord.log', "Time: {$time_delta}\n---\n{$sql}\n---\nPage url: {$_SERVER['REQUEST_URI']}\n=========================\n", FILE_APPEND); } if (!$multiple) { $result = $result->current(); if (!$result) { // Nothing found return null; } return static::_createObject($result); } if ($key !== null or $value !== null) { $result = $result->as_array($key, $value); if ($value !== null) { return $result; } } if (!count($result)) { return []; } $arr = []; foreach ($result as $key => $row) { $arr[$key] = static::_createObject($row); } return $arr; }
public static function count(array $criteria, $connection = NULL) { unset($criteria['LIMIT'], $criteria['OFFSET'], $criteria['ORDER_BY']); $criteria['SELECT'] = ['COUNT(*) cnt']; return (int) \DB::find($criteria)->execute($connection)->get('cnt'); }