Model::addBindParam
Add Bind Parameter types
Description
public self Model::addBindParam( string $column, string $type )
The value of the column is cast to the type before it is written by insertRow, insertRows, updateRow, updateRowsWhere, insert, update and updateWhere. null values are not cast. Reads are not affected.
Throws InvalidArgumentException for an unknown type.
Arguments
| Name | Data type | Default | Remarks |
|---|---|---|---|
| $column | string | Column name | |
| $type | string | Bind type (case-insensitive) |
Types
| Type | Cast |
|---|---|
INTEGER | (int) |
FLOAT | (float) |
DATE | Y-m-d. A number is read as a Unix timestamp, anything else with strtotime() |
DATETIME | Y-m-d H:i:s. A number is read as a Unix timestamp, anything else with strtotime() |
A DATE / DATETIME string that strtotime() cannot read is stored as 1970-01-01; validate dates before writing them.
Example
Controller
$model = new Model();
$model->addBindParam('category', 'INTEGER');
$model->addBindParam('image_id', 'INTEGER');
$model->addBindParam('file_id', 'INTEGER');
$model->addBindParam('post_date', 'DATETIME');
// Same as the following
$model = new Model();
$model->setBindParam(array(
'category' => 'INTEGER',
'image_id' => 'INTEGER',
'file_id' => 'INTEGER',
'post_date' => 'DATETIME',
));