Database expressions can be used to add unescaped SQL fragments to a Database_Query_Builder object.
For example, you can use an expression to generate a column alias:
// SELECT CONCAT(first_name, last_name) AS full_name
$query
= DB::select(
array
(DB::expr(
'CONCAT(first_name, last_name)'
),
'full_name'
)));
More examples are available on the Query Builder page
Class declared in MODPATH/database/classes/kohana/database/expression.php on line 19.
$_valuelink to thisSets the expression string.
$expression
=
new
Database_Expression(
'COUNT(users.id)'
);
void
public
function
__construct(
$value
)
{
// Set the expression string
$this
->_value =
$value
;
}
Return the value of the expression as a string.
echo
$expression
;
string
public
function
__toString()
{
return
$this
->value();
}
Get the expression value as a string.
$sql
=
$expression
->value();
string
public
function
value()
{
return
(string)
$this
->_value;
}