MathBinder
in package
implements
PdbDataBinderInterface
A data binder for performing math operations on update.
Note, if used for an insert the whole 'value' is inserted without any operation.
E.g.
$update = [
'date_modified' => Pdb::now(),
'counter' => MathBinder::add(10),
];
Pdb::update('my_table', $update, ['id' => $id]);
Table of Contents
Interfaces
- PdbDataBinderInterface
- This defines how values are formatted and bound to queries.
Constants
- OPERATOR_ADD : mixed = '+'
- OPERATOR_DIVIDE : mixed = '/'
- OPERATOR_MODULO : mixed = '%'
- OPERATOR_MULTIPLY : mixed = '*'
- OPERATOR_SUBTRACT : mixed = '-'
- OPERATORS : mixed = [self::OPERATOR_ADD, self::OPERATOR_SUBTRACT, s...
Properties
Methods
- __construct() : mixed
- Use the the shorthand add/subtract/etc helpers.
- add() : self
- Add a value to the column.
- divide() : self
- Divide the column by this value.
- getBindingQuery() : string
- Get the SQL snippet for an `UPDATE SET` query.
- getBindingValue() : string|int|float|object
- Get the value to bind to a query.
- modulo() : self
- Perform a remainder division on the column.
- multiply() : self
- Multiply the column by this value.
- subtract() : self
- Subtract a value from the column.
Constants
OPERATOR_ADD
public
mixed
OPERATOR_ADD
= '+'
OPERATOR_DIVIDE
public
mixed
OPERATOR_DIVIDE
= '/'
OPERATOR_MODULO
public
mixed
OPERATOR_MODULO
= '%'
OPERATOR_MULTIPLY
public
mixed
OPERATOR_MULTIPLY
= '*'
OPERATOR_SUBTRACT
public
mixed
OPERATOR_SUBTRACT
= '-'
OPERATORS
public
mixed
OPERATORS
= [self::OPERATOR_ADD, self::OPERATOR_SUBTRACT, self::OPERATOR_MULTIPLY, self::OPERATOR_DIVIDE, self::OPERATOR_MODULO]
Properties
$inverse
public
bool
$inverse
$operator
public
string
$operator
$value
public
int|float
$value
Methods
__construct()
Use the the shorthand add/subtract/etc helpers.
public
__construct(int|float $value, string $operator, bool $inverse) : mixed
Parameters
- $value : int|float
- $operator : string
-
one of
self::OPERATORS - $inverse : bool
-
swap the operation:
{value} X {column}
add()
Add a value to the column.
public
static add(int|float $value[, bool $inverse = false ]) : self
Note, inverse here is pointless.
Parameters
- $value : int|float
- $inverse : bool = false
Return values
selfdivide()
Divide the column by this value.
public
static divide(int|float $value[, bool $inverse = false ]) : self
Parameters
- $value : int|float
- $inverse : bool = false
Return values
selfgetBindingQuery()
Get the SQL snippet for an `UPDATE SET` query.
public
getBindingQuery(Pdb $pdb, string $column) : string
Parameters
- $pdb : Pdb
- $column : string
Tags
Return values
stringgetBindingValue()
Get the value to bind to a query.
public
getBindingValue() : string|int|float|object
Tags
Return values
string|int|float|objectmodulo()
Perform a remainder division on the column.
public
static modulo(int|float $value[, bool $inverse = false ]) : self
Parameters
- $value : int|float
- $inverse : bool = false
Return values
selfmultiply()
Multiply the column by this value.
public
static multiply(int|float $value[, bool $inverse = false ]) : self
Parameters
- $value : int|float
- $inverse : bool = false
Return values
selfsubtract()
Subtract a value from the column.
public
static subtract(int|float $value[, bool $inverse = false ]) : self
Parameters
- $value : int|float
- $inverse : bool = false