Constants

AS_ARRAY

AS_ARRAY

Constants to set individual row data type

AS_OBJECT

AS_OBJECT

AS_RECORD

AS_RECORD

Properties

$table

$table : string

Table name

Type

string

$prefix

$prefix : string

Table prefix

Type

string

$primaryKeys

$primaryKeys : array

Primary keys

Type

array

$isNew

$isNew : boolean

Is new record flag

Type

boolean

$with

$with : array

With relationships

Type

array

$withOptions

$withOptions : array

With relationship options

Type

array

$relationships

$relationships : array

Relationships

Type

array

$jsonFields

$jsonFields : array

JSON-encoded fields

Type

array

$phpFields

$phpFields : array

PHP-serialized fields

Type

array

$base64Fields

$base64Fields : array

Base64-encoded fields

Type

array

$hashFields

$hashFields : array

Password-hashed fields

Type

array

$encryptedFields

$encryptedFields : array

Encrypted fields

Type

array

$hashAlgorithm

$hashAlgorithm : string

Hash algorithm

Type

string

$hashOptions

$hashOptions : array

Hash options ('salt', 'cost')

Type

array

$cipherMethod

$cipherMethod : string

Cipher method

Type

string

$key

$key : string

Encrypted field key

Type

string

$iv

$iv : string

Encrypted field IV (base64-encoded)

Type

string

Methods

__construct()

__construct() 

Constructor

Instantiate the database record object

Optional parameters are an array of column values, db adapter, or a table name

Throws

\Pop\Db\Exception

hasDb()

hasDb() : boolean

Check for a DB adapter

Returns

boolean

setDb()

setDb(\Pop\Db\Adapter\AbstractAdapter  $db, string  $prefix = null, boolean  $isDefault = false) : void

Set DB adapter

Parameters

\Pop\Db\Adapter\AbstractAdapter $db
string $prefix
boolean $isDefault

getSql()

getSql() : \Pop\Db\Sql

Get SQL builder

Returns

\Pop\Db\Sql

sql()

sql() : \Pop\Db\Sql

Get SQL builder (alias)

Returns

\Pop\Db\Sql

table()

table() : string

Get table name

Returns

string

findById()

findById(mixed  $id) : static|\Pop\Db\Record\Collection

Find by ID static method

Parameters

mixed $id

Returns

static|\Pop\Db\Record\Collection

findOne()

findOne(array  $columns = null, array  $options = null) : static

Find one static method

Parameters

array $columns
array $options

Returns

static

findOneOrCreate()

findOneOrCreate(array  $columns = null, array  $options = null) : static

Find one or create static method

Parameters

array $columns
array $options

Returns

static

findLatest()

findLatest(string  $by = null, array  $columns = null, array  $options = null) : static

Find latest static method

Parameters

string $by
array $columns
array $options

Returns

static

findBy()

findBy(array  $columns = null, array  $options = null, string  $resultAs = \Pop\Db\Record::AS_RECORD) : \Pop\Db\Record\Collection

Find by static method

Parameters

array $columns
array $options
string $resultAs

Returns

\Pop\Db\Record\Collection

findByOrCreate()

findByOrCreate(array  $columns = null, array  $options = null, string  $resultAs = \Pop\Db\Record::AS_RECORD) : \Pop\Db\Record\Collection|\Pop\Db\Record

Find by or create static method

Parameters

array $columns
array $options
string $resultAs

Returns

\Pop\Db\Record\Collection|\Pop\Db\Record

findAll()

findAll(array  $options = null, string  $resultAs = \Pop\Db\Record::AS_RECORD) : \Pop\Db\Record\Collection

Find all static method

Parameters

array $options
string $resultAs

Returns

\Pop\Db\Record\Collection

execute()

execute(mixed  $sql, array  $params, string  $resultAs = \Pop\Db\Record::AS_RECORD) : \Pop\Db\Record\Collection

Static method to execute a custom prepared SQL statement.

Parameters

mixed $sql
array $params
string $resultAs

Returns

\Pop\Db\Record\Collection

query()

query(mixed  $sql, string  $resultAs = \Pop\Db\Record::AS_RECORD) : \Pop\Db\Record\Collection

Static method to execute a custom SQL query.

Parameters

mixed $sql
string $resultAs

Returns

\Pop\Db\Record\Collection

with()

with(mixed  $name, array  $options = null) : static

With a 1:many relationship (eager-loading)

Parameters

mixed $name
array $options

Returns

static

getTotal()

getTotal(array  $columns = null) : integer

Static method to get the total count of a set from the DB table

Parameters

array $columns

Returns

integer

getTableInfo()

getTableInfo() : array

Static method to get the total count of a set from the DB table

Returns

array

getById()

getById(mixed  $id) : static|\Pop\Db\Record\Collection

Get by ID method

Parameters

mixed $id

Returns

static|\Pop\Db\Record\Collection

getOneBy()

getOneBy(array  $columns = null, array  $options = null) : static

Get one method

Parameters

array $columns
array $options

Returns

static

getBy()

getBy(array  $columns = null, array  $options = null, string  $resultAs = \Pop\Db\Record::AS_RECORD) : \Pop\Db\Record\Collection

Get by method

Parameters

array $columns
array $options
string $resultAs

Returns

\Pop\Db\Record\Collection

getAll()

getAll(array  $options = null, string  $resultAs = \Pop\Db\Record::AS_RECORD) : \Pop\Db\Record\Collection

Get all method

Parameters

array $options
string $resultAs

Returns

\Pop\Db\Record\Collection

hasOne()

hasOne(string  $foreignTable, string  $foreignKey, array  $options = null, boolean  $eager = false) : \Pop\Db\Record|\Pop\Db\Record\Relationships\HasOne

Has one relationship

Parameters

string $foreignTable
string $foreignKey
array $options
boolean $eager

Returns

\Pop\Db\Record|\Pop\Db\Record\Relationships\HasOne

hasOneOf()

hasOneOf(string  $foreignTable, string  $foreignKey, array  $options = null, boolean  $eager = false) : \Pop\Db\Record|\Pop\Db\Record\Relationships\HasOne

Has one of relationship

Parameters

string $foreignTable
string $foreignKey
array $options
boolean $eager

Returns

\Pop\Db\Record|\Pop\Db\Record\Relationships\HasOne

hasMany()

hasMany(string  $foreignTable, string  $foreignKey, array  $options = null, boolean  $eager = false) : \Pop\Db\Record\Collection|\Pop\Db\Record\Relationships\HasMany

Has many relationship

Parameters

string $foreignTable
string $foreignKey
array $options
boolean $eager

Returns

\Pop\Db\Record\Collection|\Pop\Db\Record\Relationships\HasMany

belongsTo()

belongsTo(string  $foreignTable, string  $foreignKey, array  $options = null, boolean  $eager = false) : \Pop\Db\Record|\Pop\Db\Record\Relationships\BelongsTo

Belongs to relationship

Parameters

string $foreignTable
string $foreignKey
array $options
boolean $eager

Returns

\Pop\Db\Record|\Pop\Db\Record\Relationships\BelongsTo

increment()

increment(string  $column, integer  $amount = 1) : void

Increment the record column and save

Parameters

string $column
integer $amount

decrement()

decrement(string  $column, integer  $amount = 1) : void

Decrement the record column and save

Parameters

string $column
integer $amount

replicate()

replicate(array  $replace = array()) : static

Replicate the record

Parameters

array $replace

Returns

static

isDirty()

isDirty() : boolean

Check if row is dirty

Returns

boolean

getDirty()

getDirty() : array

Get row's dirty columns

Returns

array

save()

save(array  $columns = null) : void

Save the record

Parameters

array $columns

delete()

delete(array  $columns = null) : void

Delete the record

Parameters

array $columns

__callStatic()

__callStatic(string  $name, array  $arguments) : mixed

Call static method

Parameters

string $name
array $arguments

Returns

mixed

setTable()

setTable(string  $table) : \Pop\Db\Record\AbstractRecord

Set the table

Parameters

string $table

Returns

\Pop\Db\Record\AbstractRecord

setTableFromClassName()

setTableFromClassName(string  $class) : mixed

Set the table from a class name

Parameters

string $class

Returns

mixed

setPrefix()

setPrefix(string  $prefix) : \Pop\Db\Record\AbstractRecord

Set the table prefix

Parameters

string $prefix

Returns

\Pop\Db\Record\AbstractRecord

setPrimaryKeys()

setPrimaryKeys(array  $keys) : \Pop\Db\Record\AbstractRecord

Set the primary keys

Parameters

array $keys

Returns

\Pop\Db\Record\AbstractRecord

addWith()

addWith(string  $name, array  $options = null) : \Pop\Db\Record\AbstractRecord

Set with relationships

Parameters

string $name
array $options

Returns

\Pop\Db\Record\AbstractRecord

hasWith()

hasWith(string  $name) : boolean

Determine if there is specific with relationship

Parameters

string $name

Returns

boolean

hasWiths()

hasWiths() : boolean

Determine if there are with relationships

Returns

boolean

getWiths()

getWiths() : array

Get with relationships

Returns

array

getWithRelationships()

getWithRelationships(boolean  $eager = true) : \Pop\Db\Record\AbstractRecord

Get with relationships

Parameters

boolean $eager

Returns

\Pop\Db\Record\AbstractRecord

setRelationship()

setRelationship(string  $name, mixed  $relationship) : \Pop\Db\Record\AbstractRecord

Set relationship

Parameters

string $name
mixed $relationship

Returns

\Pop\Db\Record\AbstractRecord

getRelationship()

getRelationship(string  $name) : mixed

Get relationship

Parameters

string $name

Returns

mixed

hasRelationship()

hasRelationship(string  $name) : boolean

Has relationship

Parameters

string $name

Returns

boolean

getRelationships()

getRelationships() : array

Get relationships

Returns

array

getTable()

getTable() : string

Get the table

Returns

string

getFullTable()

getFullTable() : string

Get the full table name (prefix + table)

Returns

string

getPrefix()

getPrefix() : string

Get the table prefix

Returns

string

getPrimaryKeys()

getPrimaryKeys() : array

Get the primary keys

Returns

array

getPrimaryValues()

getPrimaryValues() : array

Get the primary values

Returns

array

getRowGateway()

getRowGateway() : \Pop\Db\Gateway\Row

Get the row gateway

Returns

\Pop\Db\Gateway\Row

getTableGateway()

getTableGateway() : \Pop\Db\Gateway\Table

Get the table gateway

Returns

\Pop\Db\Gateway\Table

toArray()

toArray() : array

Get column values as array

Returns

array

toArrayObject()

toArrayObject() : \ArrayObject

Get column values as array object

Returns

\ArrayObject

count()

count() : integer

Method to get count of fields in row gateway

Returns

integer

getIterator()

getIterator() : \ArrayIterator

Method to iterate over the columns

Returns

\ArrayIterator

countRows()

countRows() : integer

Get the count of rows returned in the result

Returns

integer

hasRows()

hasRows() : boolean

Determine if the result has rows

Returns

boolean

setColumns()

setColumns(mixed  $columns = null) : \Pop\Db\Record\Encoded

Set all the table column values at once

Parameters

mixed $columns

Throws

\Pop\Db\Record\Exception

Returns

\Pop\Db\Record\Encoded

setRows()

setRows(array  $rows = null, string  $resultAs = \Pop\Db\Record\AbstractRecord::AS_RECORD) : \Pop\Db\Record\AbstractRecord

Set all the table rows at once

Parameters

array $rows
string $resultAs

Returns

\Pop\Db\Record\AbstractRecord

processRows()

processRows(array  $rows, string  $resultAs = \Pop\Db\Record\AbstractRecord::AS_RECORD) : array

Process table rows

Parameters

array $rows
string $resultAs

Returns

array

processRow()

processRow(array  $row, string  $resultAs = \Pop\Db\Record\AbstractRecord::AS_RECORD) : mixed

Process a table row

Parameters

array $row
string $resultAs

Returns

mixed

__set()

__set(string  $name, mixed  $value) : void

Magic method to set the property to the value of $this->rowGateway[$name]

Parameters

string $name
mixed $value

__get()

__get(string  $name) : mixed

Magic method to return the value of $this->rowGateway[$name]

Parameters

string $name

Returns

mixed

__isset()

__isset(string  $name) : boolean

Magic method to return the isset value of $this->rowGateway[$name]

Parameters

string $name

Returns

boolean

__unset()

__unset(string  $name) : void

Magic method to unset $this->rowGateway[$name]

Parameters

string $name

offsetExists()

offsetExists(mixed  $offset) : boolean

ArrayAccess offsetExists

Parameters

mixed $offset

Returns

boolean

offsetGet()

offsetGet(mixed  $offset) : mixed

ArrayAccess offsetGet

Parameters

mixed $offset

Returns

mixed

offsetSet()

offsetSet(mixed  $offset, mixed  $value) : void

ArrayAccess offsetSet

Parameters

mixed $offset
mixed $value

offsetUnset()

offsetUnset(mixed  $offset) : void

ArrayAccess offsetUnset

Parameters

mixed $offset

encodeValue()

encodeValue(string  $key, mixed  $value) : string

Encode value

Parameters

string $key
mixed $value

Throws

\Pop\Db\Record\Exception

Returns

string

decodeValue()

decodeValue(string  $key, string  $value) : mixed

Decode value

Parameters

string $key
string $value

Throws

\Pop\Db\Record\Exception

Returns

mixed

verify()

verify(string  $key, string  $value) : boolean

Verify value against hash

Parameters

string $key
string $value

Returns

boolean

encode()

encode(array  $columns) : array

Scrub the column values and encode them

Parameters

array $columns

Returns

array

decode()

decode(array  $columns) : array

Scrub the column values and decode them

Parameters

array $columns

Returns

array

isEncodedColumn()

isEncodedColumn(string  $key) : boolean

Determine if column is an encoded column

Parameters

string $key

Returns

boolean