\Gishiki\Database\Adapters\Utils\SQLGeneratorMySQLWrapper

This utility is useful to create sql queries for MySQL.

It extends the SQLQueryBuilder and add MySQL-specific support.

Summary

Methods
Properties
Constants
beautify()
__construct()
update()
set()
createTable()
dropTable()
where()
insertInto()
values()
limitOffsetOrderBy()
selectAllFrom()
selectFrom()
deleteFrom()
exportQuery()
exportParams()
definedAs()
No public properties found
No constants found
appendToQuery()
appendToParams()
$sql
$params
N/A
No private methods found
No private properties found
N/A

Properties

$sql

$sql : string

Type

string — the SQL query that contains placeholders

$params

$params : array

Type

array — a list of values to be escaped and inserted in place of sql placeholders

Methods

beautify()

beautify(string  $query) : string

Beautify an SQL query.

Parameters

string $query

your ugly SQL query

Returns

string —

your beautiful SQL query

__construct()

__construct() 

Initialize an empty SQL query.

set()

set(array  $values) : \Gishiki\Database\Adapters\Utils\SQLGenerator\SQLWrapperInterface

Add SET col1 = ?, col2 = ?, col3 = ? to the SQL query.

Parameters

array $values

an associative array of columns => value to be changed

Returns

\Gishiki\Database\Adapters\Utils\SQLGenerator\SQLWrapperInterface

the updated sql builder

createTable()

createTable(string  $tableName) : \Gishiki\Database\Adapters\Utils\SQLGenerator\SQLWrapperInterface

Add CREATE TABLE IF NOT EXISTS %tablename% to the SQL query.

Parameters

string $tableName

the name of the table

Returns

\Gishiki\Database\Adapters\Utils\SQLGenerator\SQLWrapperInterface

the updated sql builder

values()

values(array  $values) : \Gishiki\Database\Adapters\Utils\SQLGenerator\SQLWrapperInterface

Add (col1, col2, col3) VALUES (?, ?, ?, ?) to the SQL query.

Parameters

array $values

an associative array of columnName => rowValue

Returns

\Gishiki\Database\Adapters\Utils\SQLGenerator\SQLWrapperInterface

the updated sql builder

selectAllFrom()

selectAllFrom(string  $table) : \Gishiki\Database\Adapters\Utils\SQLGenerator\SQLWrapperInterface

Add SELECT * FROM %tablename% to the SQL query.

Parameters

string $table

the name of the table to be affected

Returns

\Gishiki\Database\Adapters\Utils\SQLGenerator\SQLWrapperInterface

the updated sql builder

selectFrom()

selectFrom(string  $table, array  $fields) : \Gishiki\Database\Adapters\Utils\SQLGenerator\SQLWrapperInterface

Add SELECT col1, col2, col3 FROM %tablename% to the SQL query.

Parameters

string $table

the name of the table to be affected

array $fields

the list containing names of columns to be selected

Returns

\Gishiki\Database\Adapters\Utils\SQLGenerator\SQLWrapperInterface

the updated sql builder

exportQuery()

exportQuery() : string

Export the SQL query string with ? in place of actual parameters.

Returns

string —

the SQL query without values

exportParams()

exportParams() : array

Export the list of parameters that will replace ? in the SQL query.

Returns

array —

the list of params

definedAs()

definedAs(array  $columns) : \Gishiki\Database\Adapters\Utils\SQLGenerator\SQLWrapperInterface

Add (id INTEGER PRIMARY KEY NUT NULL, name TEXT NOT NULL, .

.. ) to the SQL query.

Parameters

array $columns

a collection of Gishiki\Database\Schema\Column

Returns

\Gishiki\Database\Adapters\Utils\SQLGenerator\SQLWrapperInterface

the updated sql builder

appendToQuery()

appendToQuery(string  $sql) 

Append to the current SQL the given text.

Placeholders are question marks: ? and the value must be registered using the appendToParams function.

Parameters

string $sql

the SQL with '?' placeholders

appendToParams()

appendToParams(mixed  $newParams) 

This is a collection of raw values that the PDO will replace to ? on the SQL query.

Parameters

mixed $newParams

an array of values or the value to be replaced