\Gishiki\Database\Adapters\Utils\SQLGeneratorSQLWrapper

This utility is useful to create sql queries for various RDBMS.

An example of usage can be: $passwordHasher = new Hashing\Hasher(Hashing\Algorithm::BCRYPT);

$queryBuilder = new SQLQueryBuilder(); $queryBuilder->insertInto("users")->values([ "name" => "Mario", "surname" => "Rossi", "password" => $passwordHasher->hash("Mario's password"); // good bye rainbow tables! "sex" => 0, "height" => 1.70 ]);

//INSERT INTO "users" (name, surname, password, sex, height) VALUES (?, ?, ?, ?, ?) $sql = $queryBuilder->exportQuery();

// array( "Mario", "Rossi", ".....", 0, 1.70 ) $params = $queryBuilder->exportParams();

Summary

Methods
Properties
Constants
beautify()
__construct()
update()
set()
createTable()
dropTable()
where()
insertInto()
values()
limitOffsetOrderBy()
selectAllFrom()
selectFrom()
deleteFrom()
exportQuery()
exportParams()
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

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