Documentation

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

$inverse  : bool
$operator  : string
$value  : int|float

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_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

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
self

divide()

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
self

getBindingQuery()

Get the SQL snippet for an `UPDATE SET` query.

public getBindingQuery(Pdb $pdb, string $column) : string
Parameters
$pdb : Pdb
$column : string
Tags
inheritdoc
Return values
string

getBindingValue()

Get the value to bind to a query.

public getBindingValue() : string|int|float|object
Tags
inheritdoc
Return values
string|int|float|object

modulo()

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
self

multiply()

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
self

subtract()

Subtract a value from the column.

public static subtract(int|float $value[, bool $inverse = false ]) : self
Parameters
$value : int|float
$inverse : bool = false
Return values
self
On this page

Search results