PHP Class Pop\Db\Record

Author: Nick Sagona, III ([email protected])
Inheritance: implements ArrayAccess
Datei anzeigen Open project: nicksagona/PopPHP Class Usage Examples

Public Properties

Property Type Description
$db array Database connection(s)
$rows array Rows of multiple return results from a database query in an ArrayObject format.

Protected Properties

Property Type Description
$auto boolean Property that determines whether or not the primary ID is auto-increment or not
$columns array Column names of the database table
$interface Pop\Db\Record\AbstractRecord Record interface
$prefix string Table prefix
$primaryId string | array Primary ID column name of the database table
$tableName string Table name of the database table
$usePrepared boolean Flag on whether or not to use prepared statements

Public Methods

Method Description
__construct ( array $columns = null, Db $db = null ) : Record Constructor
__get ( string $name ) : mixed Get method to return the value of columns[$name].
__isset ( string $name ) : boolean Return the isset value of columns[$name].
__set ( string $name, mixed $value ) : void Set method to set the property to the value of columns[$name].
__unset ( string $name ) : void Unset columns[$name].
count ( ) : integer Method to return the current number of records.
delete ( array $columns = null ) : void Delete the database record.
escape ( string $value ) : string Return the escaped string value.
execute ( string $sql, array $params = null ) : Record Execute a custom prepared SQL query.
findAll ( string $order = null, array $columns = null, integer $limit = null, integer $offset = null ) : Record Find all of the database rows by the column passed through the method argument.
findBy ( array $columns, string $order = null, integer $limit = null, integer $offset = null ) : Record Find a database row by the column passed through the method argument.
findById ( mixed $id, integer $limit = null, integer $offset = null ) : Record Find a database row by the primary ID passed through the method argument.
getCount ( array $columns = null ) : mixed Get total count of records
getDb ( ) : Db Get DB connection
getFullTableName ( ) : string Get the full table name, with the prefix
getId ( ) : mixed Get the table primary ID
getPrefix ( ) : string Get the table prefix
getSql ( ) : Sql Get the SQL object.
getTableInfo ( ) : array Get table info anf return as an array.
getTableName ( ) : string Get the abbreviated table name, without the prefix
getValues ( ) : array Get all the table column values at once as an associative array.
isAuto ( ) : boolean Get if the table is an autoincrement table
isPrepared ( ) : boolean Get if the record interface is prepared or not
lastId ( ) : integer Return the auto-increment ID of the last query.
numFields ( ) : integer Return the number of fields in the result.
numRows ( ) : integer Return the number of rows in the result.
query ( string $sql ) : Record Execute a custom SQL query.
save ( integer $type = Record::INSERT ) : void Save the database record.
setDb ( Db $db, boolean $isDefault = false ) : void Set DB connection
setValues ( array $columns = null ) : Record Set all the table column values at once.
update ( ) : void Update (save) the existing database record.

Protected Methods

Method Description
camelCaseToUnderscore ( string $string ) : string Method to convert a camelCase string to an under_score string
setResults ( array $result ) : void Set the query results.

Method Details

__construct() public method

Instantiate the database record object.
public __construct ( array $columns = null, Db $db = null ) : Record
$columns array
$db Db
return Record

__get() public method

Get method to return the value of columns[$name].
public __get ( string $name ) : mixed
$name string
return mixed

__isset() public method

Return the isset value of columns[$name].
public __isset ( string $name ) : boolean
$name string
return boolean

__set() public method

Set method to set the property to the value of columns[$name].
public __set ( string $name, mixed $value ) : void
$name string
$value mixed
return void

__unset() public method

Unset columns[$name].
public __unset ( string $name ) : void
$name string
return void

camelCaseToUnderscore() protected method

Method to convert a camelCase string to an under_score string
protected camelCaseToUnderscore ( string $string ) : string
$string string
return string

count() public method

Method to return the current number of records.
public count ( ) : integer
return integer

delete() public method

Delete the database record.
public delete ( array $columns = null ) : void
$columns array
return void

escape() public method

Return the escaped string value.
public escape ( string $value ) : string
$value string
return string

execute() public static method

Execute a custom prepared SQL query.
public static execute ( string $sql, array $params = null ) : Record
$sql string
$params array
return Record

findAll() public static method

Find all of the database rows by the column passed through the method argument.
public static findAll ( string $order = null, array $columns = null, integer $limit = null, integer $offset = null ) : Record
$order string
$columns array
$limit integer
$offset integer
return Record

findBy() public static method

Find a database row by the column passed through the method argument.
public static findBy ( array $columns, string $order = null, integer $limit = null, integer $offset = null ) : Record
$columns array
$order string
$limit integer
$offset integer
return Record

findById() public static method

Find a database row by the primary ID passed through the method argument.
public static findById ( mixed $id, integer $limit = null, integer $offset = null ) : Record
$id mixed
$limit integer
$offset integer
return Record

getCount() public static method

Get total count of records
public static getCount ( array $columns = null ) : mixed
$columns array
return mixed

getDb() public static method

Get DB connection
public static getDb ( ) : Db
return Db

getFullTableName() public method

Get the full table name, with the prefix
public getFullTableName ( ) : string
return string

getId() public method

Get the table primary ID
public getId ( ) : mixed
return mixed

getPrefix() public method

Get the table prefix
public getPrefix ( ) : string
return string

getSql() public static method

Get the SQL object.
public static getSql ( ) : Sql
return Sql

getTableInfo() public static method

Get table info anf return as an array.
public static getTableInfo ( ) : array
return array

getTableName() public method

Get the abbreviated table name, without the prefix
public getTableName ( ) : string
return string

getValues() public method

Get all the table column values at once as an associative array.
public getValues ( ) : array
return array

isAuto() public method

Get if the table is an autoincrement table
public isAuto ( ) : boolean
return boolean

isPrepared() public method

Get if the record interface is prepared or not
public isPrepared ( ) : boolean
return boolean

lastId() public method

Return the auto-increment ID of the last query.
public lastId ( ) : integer
return integer

numFields() public method

Return the number of fields in the result.
public numFields ( ) : integer
return integer

numRows() public method

Return the number of rows in the result.
public numRows ( ) : integer
return integer

query() public static method

Execute a custom SQL query.
public static query ( string $sql ) : Record
$sql string
return Record

save() public method

Save the database record.
public save ( integer $type = Record::INSERT ) : void
$type integer
return void

setDb() public static method

Set DB connection
public static setDb ( Db $db, boolean $isDefault = false ) : void
$db Db
$isDefault boolean
return void

setResults() protected method

Set the query results.
protected setResults ( array $result ) : void
$result array
return void

setValues() public method

Set all the table column values at once.
public setValues ( array $columns = null ) : Record
$columns array
return Record

update() public method

Update (save) the existing database record.
public update ( ) : void
return void

Property Details

$auto protected_oe property

Property that determines whether or not the primary ID is auto-increment or not
protected bool $auto
return boolean

$columns protected_oe property

Column names of the database table
protected array $columns
return array

$db public_oe static_oe property

Database connection(s)
public static array $db
return array

$interface protected_oe property

Record interface
protected AbstractRecord,Pop\Db\Record $interface
return Pop\Db\Record\AbstractRecord

$prefix protected_oe property

Table prefix
protected string $prefix
return string

$primaryId protected_oe property

Primary ID column name of the database table
protected string|array $primaryId
return string | array

$rows public_oe property

Rows of multiple return results from a database query in an ArrayObject format.
public array $rows
return array

$tableName protected_oe property

Table name of the database table
protected string $tableName
return string

$usePrepared protected_oe property

Flag on whether or not to use prepared statements
protected bool $usePrepared
return boolean