Properties

$dialect

$dialect : 

Properties

Type

$sql

$sql : 

Type

$prefix

$prefix : 

Type

$columns

$columns : 

Type

$from

$from : 

Type

$join

$join : 

Type

$where

$where : 

Type

$groupby

$groupby : 

Type

$orderby

$orderby : 

Type

$limit

$limit : 

Type

$offset

$offset : 

Type

$options

$options : 

Properties

Type

$db

$db : 

Type

$stmt

$stmt : 

Type

$numQueries

$numQueries : 

Type

$queries

$queries : 

Type

$params

$params : 

Type

Methods

getSQL()

getSQL() : string

Get SQL.

Returns

string —

as sql-query

setSQLDialect()

setSQLDialect(string  $dialect) : void

Set database type to consider when generating SQL.

Parameters

string $dialect

representing database type.

setTablePrefix()

setTablePrefix(string  $prefix) : void

Set a table prefix.

Parameters

string $prefix

to use in front of all tables.

createTable()

createTable(string  $name, array  $columns) : $this

Create a table.

Parameters

string $name

the table name.

array $columns

the columns in the table.

Returns

$this

dropTable()

dropTable(string  $name) : $this

Drop a table.

Parameters

string $name

the table name.

Returns

$this

dropTableIfExists()

dropTableIfExists(string  $name) : $this

Drop a table if it exists.

Parameters

string $name

the table name.

Returns

$this

mapColumnsWithValues()

mapColumnsWithValues(array  $columns, array|null  $values) : array

Create a proper column value arrays from incoming $columns and $values.

Parameters

array $columns
array|null $values

Returns

array —

that can be parsed with list($columns, $values)

insert()

insert(string  $table, array  $columns, array  $values = null) : void

Build a insert-query.

Parameters

string $table

the table name.

array $columns

to insert och key=>value with columns and values.

array $values

to insert or empty if $columns has both columns and values.

update()

update(string  $table, array  $columns, array  $values = null, array  $where = null) : void

Build an update-query.

Parameters

string $table

the table name.

array $columns

to update or key=>value with columns and values.

array $values

to update or empty if $columns has bot columns and values.

array $where

limit which rows are updated.

delete()

delete(string  $table, array  $where = null) : void

Build a delete-query.

Parameters

string $table

the table name.

array $where

limit which rows are updated.

select()

select(string  $columns = '*') : $this

Build a select-query.

Parameters

string $columns

which columns to select.

Returns

$this

from()

from(string  $table) : $this

Build the from part.

Parameters

string $table

name of table.

Returns

$this

join()

join(string  $table, string  $condition) : $this

Build the inner join part.

Parameters

string $table

name of table.

string $condition

to join.

Returns

$this

rightJoin()

rightJoin(string  $table, string  $condition) : $this

Build the right join part.

Parameters

string $table

name of table.

string $condition

to join.

Returns

$this

leftJoin()

leftJoin(string  $table, string  $condition) : $this

Build the left join part.

Parameters

string $table

name of table.

string $condition

to join.

Returns

$this

where()

where(string  $condition) : $this

Build the where part.

Parameters

string $condition

for building the where part of the query.

Returns

$this

andWhere()

andWhere(string  $condition) : $this

Build the where part with conditions.

Parameters

string $condition

for building the where part of the query.

Returns

$this

groupBy()

groupBy(string  $condition) : $this

Build the group by part.

Parameters

string $condition

for building the group by part of the query.

Returns

$this

orderBy()

orderBy(string  $condition) : $this

Build the order by part.

Parameters

string $condition

for building the where part of the query.

Returns

$this

limit()

limit(string  $condition) : $this

Build the LIMIT by part.

Parameters

string $condition

for building the LIMIT part of the query.

Returns

$this

offset()

offset(string  $condition) : $this

Build the OFFSET by part.

Parameters

string $condition

for building the OFFSET part of the query.

Returns

$this

__construct()

__construct(array  $options = array()) 

Constructor creating a PDO object connecting to a choosen database.

Parameters

array $options

containing details for connecting to the database.

setOptions()

setOptions(array  $options = array()) : void

Set options and connection details.

Parameters

array $options

containing details for connecting to the database.

connect()

connect(boolean  $debug = false) : void

Connect to the database.

Parameters

boolean $debug

default false, set to true to throw exception with full connection details when connection fails.

setVerbose()

setVerbose(boolean  $on = true) : void

Set and unset verbose mode to display queries made.

Parameters

boolean $on

set true to display queries made through echo, false to disable.

setFetchMode()

setFetchMode(integer  $fetchmode = null) : void

Set fetch mode. (OBSOLETE?)

Parameters

integer $fetchmode

as \PDO::FETCH_OBJ, \PDO::FETCH_CLASS, \PDO::FETCH_INTO, etc.

setFetchModeClass()

setFetchModeClass(string  $class) : boolean

Set fetchmode to insert Fetch one resultset from previous select statement as an object.

Parameters

string $class

to insert values into.

Returns

boolean —

Returns TRUE on success or FALSE on failure.

loadHistory()

loadHistory() : integer

Load query-history from session if available.

Returns

integer —

number of database queries made.

saveHistory()

saveHistory(string  $extra = null) : void

Save query-history in session, useful as a flashmemory when redirecting to another page.

Parameters

string $extra

enables to save some extra debug information.

getNumQueries()

getNumQueries() : integer

Get how many queries have been processed.

Returns

integer —

number of database queries made.

getQueries()

getQueries() : array

Get all the queries that have been processed.

Returns

array —

with queries.

dump()

dump() : string

Get a html representation of all queries made, for debugging and analysing purpose.

Returns

string —

with html.

executeFetchAll()

executeFetchAll(string  $query = null, array  $params = array()) : array

Execute a select-query with arguments and return the resultset.

Parameters

string $query

the SQL query with ?.

array $params

array which contains the argument to replace ?.

Returns

array —

with resultset.

fetchAll()

fetchAll() : array

Fetch all resultset from previous select statement.

Returns

array —

with resultset.

fetchOne()

fetchOne() : array

Fetch one resultset from previous select statement.

Returns

array —

with resultset.

fetchObject()

fetchObject(object  $class) : array

Fetch one resultset from previous select statement as an object.

Parameters

object $class

which type of object to instantiate.

Returns

array —

with resultset.

fetchInto()

fetchInto(object  $object) : array

Fetch one resultset from previous select statement as an object.

Parameters

object $object

to insert values into.

Returns

array —

with resultset.

execute()

execute(string  $query = null, array  $params = array()) : boolean

Execute a SQL-query and ignore the resultset.

Parameters

string $query

the SQL query with ?.

array $params

array which contains the argument to replace ?.

Throws

\Mos\Database\Exception

when failing to prepare question.

Returns

boolean —

returns TRUE on success or FALSE on failure.

lastInsertId()

lastInsertId() 

Return last insert id.

rowCount()

rowCount() 

Return rows affected of last INSERT, UPDATE, DELETE

build()

build() : string

Build SQL.

Returns

string —

as SQL query

clear()

clear() : void

Clear all previous sql-code.

expandParamArray()

expandParamArray(string  $query, array  $params) : array

Extend params array to support arrays in it, extract array items and add to $params and insert ? for each entry.

Parameters

string $query

as the query to prepare.

array $params

the parameters that may contain arrays.

Returns

array —

with query and params.

createJoin()

createJoin(string  $table, string  $condition, string  $type) : void

Create a inner or outer join.

Parameters

string $table

name of table.

string $condition

to join.

string $type

what type of join to create.