xPDOExpression
Last updated not available | Page history | Improve this page | Report an issue
Support the team building MODX with a monthly donation.
The budget raised through OpenCollective is transparent, including payouts, and any contributor can apply to be paid for their work on MODX.
Backers
Budget
$194 per month—let's make that $500!
Learn morexPDO\Om\xPDOExpression is an immutable value object that wraps a raw SQL fragment so xPDO can inline it verbatim instead of binding it as a parameter. Use it wherever xPDOQuery accepts a column value or a SELECT entry when you need a SQL expression — a function call (NOW(), CURRENT_TIMESTAMP), an arithmetic expression (counter + 1), or an aggregate with an alias (COUNT(*) AS total). Valid contexts include SET, SELECT, WHERE, HAVING, GROUP BY, and ORDER BY.
The expression is embedded without quoting, escaping, or parameterisation, so keeping it safe is the caller's responsibility.
[!WARNING] Never pass unsanitised user input to
xPDOExpressionor to xPDO::expression(). The string is inserted into the generated SQL as-is and can lead to SQL injection.
Creating an Expression¶
The class is final; build instances with the xPDO::expression() factory:
$expr = $xpdo->expression('NOW()');
Examples¶
Sort by a raw expression:
$query = $xpdo->newQuery('modResource');
$query->sortby($xpdo->expression('COUNT(*)'), 'DESC');
Use an expression as a bound value in WHERE:
$query = $xpdo->newQuery('modResource');
$query->where(array(
'createdon:<=' => $xpdo->expression('NOW()'),
));
See Also¶
Support the team building MODX with a monthly donation.
The budget raised through OpenCollective is transparent, including payouts, and any contributor can apply to be paid for their work on MODX.
Backers
Budget
$194 per month—let's make that $500!
Learn more










