Properties

$dialect

$dialect : 

Type

— current database dialect used

$sql

$sql : 

Type

$prefix

$prefix : 

Type

$start

$start : 

Type

— first line of the sql query

$from

$from : 

Type

$join

$join : 

Type

$set

$set : 

Type

$where

$where : 

Type

$groupby

$groupby : 

Type

$orderby

$orderby : 

Type

$limit

$limit : 

Type

$offset

$offset : 

Type

Methods

getSQL()

getSQL() : string

Get SQL.

Returns

string —

with the built sql-query

setSQLDialect()

setSQLDialect(string  $dialect) : self

Set database type/dialect to consider when generating SQL.

Parameters

string $dialect

representing database type.

Returns

self

setTablePrefix()

setTablePrefix(string  $prefix) : self

Set a table prefix.

Parameters

string $prefix

to use in front of all tables.

Returns

self

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

insert()

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

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.

Throws

\Anax\Database\BuildException

Returns

self —

for chaining

update()

update(string  $table, array  $columns, array  $values = 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.

Throws

\Anax\Database\BuildException

deleteFrom()

deleteFrom(string  $table, array  $where = null) : self

Build a delete-query.

Parameters

string $table

the table name.

array $where

limit which rows are updated.

Returns

self

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.

Throws

\Anax\Database\BuildException

when dialect does not support.

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

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)

build()

build() : string

Build the SQL query from its parts.

Returns

string —

as SQL query

clear()

clear() : void

Clear all previous sql-code.

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.