Database - rbertram90/core GitHub Wiki
Summary
Documentation for src/Database.php
Contents
- connect
- getConnection
- getLastInsertID
- query
- runPreparedStatement
- selectSingleRow
- selectMultipleRows
- selectAllRows
- countRows
- insertRow
- updateRow
- deleteRow
Public Methods
connect
Supply connection information and get database connection object in return
PDO connect(string $server, string $name, string $user, string $password)
getConnection
Get the current database connection object - connect() must have already been called
PDO getConnection()
getLastInsertID
Get the ID of the last insert into the database. Note - has limited use as a public method as needs to be called within database transaction.
int getLastInsertID()
query
Run a raw sql string - recommended to use the helper functions for simple queries and this for more complicated ones
PDOStatement query(string $queryString)
runPreparedStatement
Run prepared statement SQL (that is already formatted with placeholders) with $values to pass through. Returns the result of the execution
PDOStatement runPreparedStatement(string $queryString, array $values)
selectSingleRow
Select a single row from database as an associative array $columnsToSelect can be passed as an array or a string (e.g. '*')
array selectSingleRow(string $tableName, mixed $columnsToSelect, array $where[, string $strOrderBy = '' [, string $strLimit='']])
selectMultipleRows
Select multiple rows from database as a multi-dimentional associative array $columnsToSelect can be passed as an array or a string (e.g. '*')
array selectMultipleRows(string $tableName, mixed $columnsToSelect, array $where, [string $strOrderBy = '' [, string $strLimit='']])
selectAllRows
Shorthand method for selecting all rows in a table
array selectAllRows(string $tableName, mixed $columnsToSelect, [string $strOrderBy = ''])
countRows
Get a row count
int countRows(string $tableName, array $where='')
insertRow
Insert a new row into a database table. Returns true if successful, false otherwise
bool insertRow(string $tableName, array $values)
updateRow
Update existing row(s) in a database table. Returns true if successful, false otherwise
bool updateRow(string $tableName, array $where, array $values)
deleteRow
Delete row(s) in a database table
PDOStatement deleteRow(string $tableName, array $where)