Common mathematical operations with PDOdb helpers.
use tommyknocker\pdodb\helpers\Db;
// Increment by 1 (default)
$db->find()->table('users')->where('id', 1)->update([
'counter' => Db::inc()
]);
// Increment by specific amount
$db->find()->table('users')->where('id', 1)->update([
'score' => Db::inc(5)
]);// Decrement by 1 (default)
$db->find()->table('users')->where('id', 1)->update([
'stock' => Db::dec()
]);
// Decrement by specific amount
$db->find()->table('users')->where('id', 1)->update([
'credits' => Db::dec(10)
]);$users = $db->find()
->from('transactions')
->select(['amount' => Db::abs('amount')])
->get();$products = $db->find()
->from('products')
->select(['price' => Db::round('price', 2)])
->get();$users = $db->find()
->from('users')
->select(['remainder' => Db::mod('score', 10)])
->get();// Add 100 points
$db->find()->table('users')->where('id', $userId)->update([
'score' => Db::inc(100)
]);// Reduce stock by quantity
$db->find()
->table('products')
->where('id', $productId)
->update(['stock' => Db::dec($quantity)]);- String Helpers - String operations
- Date Helpers - Date/time functions
- Core Helpers - Essential helpers