- Seme Framework
- Credits
- Version 3.2.X
- Issue
- Deployment
Get First Method
The get_first
method is a part of the query builder which is useful for pulling single results from the query builder that has been compiled.
This method will only return maximum 1 row result.
Basic Usage
Here is the basic usage get_first
method from $db
property on SENE_Model class.
$this->db->get_first([string $result_type="" [, bool $is_debug = 0]]): mixed
Parameters
This method has 2 optional parameters.
$result_type
The value of the $result_type
parameter to determine the output of the get method.
Fill with string "array"
to return the result value with data type array of array.
While the contents of other values to return values with data type array of objects.
$is_debug
The $is_debug
parameter is a marker (flag) to enable debug mode.
The value of this parameter can be filled with int 1
to enable debug mode and display the query to be processed.
Fill it with another value to not enable debug mode.
In debug mode, there will be no query execution process to the database system.
Example
Here is the example for get_first
in a model class.
class D_Blog_Model extends SENE_Model{
var $tbl = 'blog';
var $tbl_as = 'b';
public function __construct(){
parent::__construct();
}
public function getBySlug($slug){
$this->db->from($this->tbl,$this->tbl_as);
$this->db->where("slug", $this->db->esc($slug));
return $this->db->get_first();
}
...
}
SQL Result
The following is the SQL command that generated from D_Blog_Model
class methods.
-- result from executing D_Blog_Model::getBySlug('seme-framework-tutorial-1') --
SELECT *
FROM `d_blog` b
WHERE
`slug` = 'seme-framework-tutorial-1'
LIMIT 0, 1;