Orpheus

MySqlAdapter extends AbstractSqlAdapter
in package

The MYSQL Adapter class

This class is the sql adapter for MySQL.

Table of Contents

Constants

ARR_OBJECTS  = 4
CONFIG  = 'database'
DEFAULT_INSTANCE  = 'default'
FETCH_ALL_COLUMNS  = \Orpheus\SqlAdapter\AbstractSqlAdapter::PROCESS_QUERY | 0 << 3
FETCH_FIRST_COLUMN  = \Orpheus\SqlAdapter\AbstractSqlAdapter::PROCESS_QUERY | 1 << 3
NUMBER  = 7
PROCESS_EXEC  = 1
PROCESS_QUERY  = 0
QUERY_FETCH_ALL  = \Orpheus\SqlAdapter\AbstractSqlAdapter::PROCESS_QUERY | 1 << 2
QUERY_FETCH_ONE  = \Orpheus\SqlAdapter\AbstractSqlAdapter::PROCESS_QUERY | 0 << 2
QUERY_STATEMENT  = \Orpheus\SqlAdapter\AbstractSqlAdapter::PROCESS_QUERY | 1 << 1
RETURN_ARRAY_ASSOC  = 3
RETURN_ARRAY_FIRST  = 2
RETURN_OBJECT  = 1
SQL_QUERY  = 6
STATEMENT  = 5

Properties

$adapters  : array<string|int, mixed>
Store drivers' adapter
$config  : array<string|int, mixed>
$configs  : array<string|int, mixed>|null
Configurations
$defaultIdField  : string
The ID field
$deleteDefaults  : array<string|int, mixed>
Delete defaults options
$insertDefaults  : array<string|int, mixed>
Insert defaults options
$instances  : array<string|int, AbstractSqlAdapter>
All Adapter instances by name
$pdo  : PDO|null
The PDO instance
$selectDefaults  : array<string|int, mixed>
Select defaults options
$updateDefaults  : array<string|int, mixed>
Update defaults options

Methods

__construct()  : mixed
Constructor
delete()  : int
Delete something in database
endTransaction()  : AbstractSqlAdapter
ensureConnection()  : void
escapeIdentifier()  : string
Escapes the given string as an SQL identifier.
escapeValue()  : string
Escape the given value to the matching SQL type.
formatString()  : string
Format the given string as an SQL string.
formatValue()  : string
Format SQL value
formatValueList()  : string
Format a list of values
getConfig()  : array<string|int, mixed>
getDriver()  : string
Get the driven string
getInstance()  : AbstractSqlAdapter
getPdo()  : PDO|null
insert()  : int
Insert something in database
isConnected()  : bool
lastId()  : string|null
Get the last inserted ID It requires a successful call of insert() !
listConfig()  : array<string|int, mixed>
List all instance's configuration
make()  : AbstractSqlAdapter
Try to make a AbstractSqlAdapter by its name loading from configuration.
prepareQuery()  : void
Prepare the query for the given instance
query()  : mixed
Query the DB server
registerAdapter()  : void
Register a driver adapter
revertTransaction()  : AbstractSqlAdapter
select()  : mixed
Select data from tables in database
setDefaultIdField()  : static
Set the id field
startTransaction()  : AbstractSqlAdapter
update()  : int
Update something in database Using pdo_query(), It parses the query from an array to a UPDATE query.
connect()  : void
Connect to the DBMS
executeRawQuery()  : mixed
formatFieldList()  : string
Format the given $fields into an escaped SQL string list of key=value
formatWhere()  : string
getDefaults()  : array<string|int, mixed>
Get defaults configuration to fill missing options
parseJoin()  : string
Parse join option to generate join
processPdoException()  : void
registerInstance()  : void
Register a unique instance by its name

Constants

FETCH_ALL_COLUMNS

public mixed FETCH_ALL_COLUMNS = \Orpheus\SqlAdapter\AbstractSqlAdapter::PROCESS_QUERY | 0 << 3

FETCH_FIRST_COLUMN

public mixed FETCH_FIRST_COLUMN = \Orpheus\SqlAdapter\AbstractSqlAdapter::PROCESS_QUERY | 1 << 3

QUERY_FETCH_ALL

public mixed QUERY_FETCH_ALL = \Orpheus\SqlAdapter\AbstractSqlAdapter::PROCESS_QUERY | 1 << 2

QUERY_FETCH_ONE

public mixed QUERY_FETCH_ONE = \Orpheus\SqlAdapter\AbstractSqlAdapter::PROCESS_QUERY | 0 << 2

QUERY_STATEMENT

public mixed QUERY_STATEMENT = \Orpheus\SqlAdapter\AbstractSqlAdapter::PROCESS_QUERY | 1 << 1

Properties

$adapters

Store drivers' adapter

protected static array<string|int, mixed> $adapters = ['mysql' => \Orpheus\SqlAdapter\Adapter\MySqlAdapter::class, 'mssql' => \Orpheus\SqlAdapter\Adapter\MsSqlAdapter::class]

$configs

Configurations

protected static array<string|int, mixed>|null $configs = null

$deleteDefaults

Delete defaults options

protected static array<string|int, mixed> $deleteDefaults = [ 'lowpriority' => false, //false => Not low priority 'quick' => false, //false => Not merge index leaves 'ignore' => false, //false => Not ignore errors 'where' => '', //Additional Whereclause 'orderby' => '', //Ex: Field1 ASC, Field2 DESC 'number' => -1, //-1 => All 'offset' => 0, //0 => The start 'output' => \Orpheus\SqlAdapter\AbstractSqlAdapter::NUMBER, ]

$insertDefaults

Insert defaults options

protected static array<string|int, mixed> $insertDefaults = [ 'lowpriority' => false, //false => Not low priority 'delayed' => false, //false => Not delayed 'ignore' => false, //false => Not ignore errors 'into' => true, //true => INSERT INTO 'output' => \Orpheus\SqlAdapter\AbstractSqlAdapter::NUMBER, ]

$selectDefaults

Select defaults options

protected static array<string|int, mixed> $selectDefaults = [ 'what' => '', // table.* => All fields 'join' => '', // No join 'where' => '', // Additional Whereclause 'orderby' => '', // Ex: Field1 ASC, Field2 DESC 'groupby' => '', // Ex: Field 'number' => -1, // -1 => All 'offset' => 0, // 0 => The start 'output' => \Orpheus\SqlAdapter\AbstractSqlAdapter::RETURN_ARRAY_ASSOC, // Associative Array 'alias' => null, // No alias 'distinct' => null, ]

$updateDefaults

Update defaults options

protected static array<string|int, mixed> $updateDefaults = [ 'lowpriority' => false, //false => Not low priority 'ignore' => false, //false => Not ignore errors 'where' => '', //Additional Whereclause 'orderby' => '', //Ex: Field1 ASC, Field2 DESC 'number' => -1, //-1 => All 'offset' => 0, //0 => The start 'output' => \Orpheus\SqlAdapter\AbstractSqlAdapter::NUMBER, ]

Methods

__construct()

Constructor

public __construct(string $name, array<string|int, mixed> $config) : mixed
Parameters
$name : string

The name of the instance

$config : array<string|int, mixed>

Instance config array

delete()

Delete something in database

public delete([array<string|int, mixed> $options = [] ]) : int
Parameters
$options : array<string|int, mixed> = []

The options used to build the query.

Tags
throws
Exception
Return values
int

The number of deleted rows.

It parses the query from an array to a DELETE query.

escapeIdentifier()

Escapes the given string as an SQL identifier.

public escapeIdentifier(string $identifier) : string
Parameters
$identifier : string

The identifier to escape

Return values
string

The escaped identifier

escapeValue()

Escape the given value to the matching SQL type.

public escapeValue(mixed $value) : string

If the value is a float, we make french decimal compatible with SQL. If null, we use the NULL value, else we consider it as a string value.

Parameters
$value : mixed

The value to format

Return values
string

The formatted value

formatString()

Format the given string as an SQL string.

public formatString(string $string) : string
Parameters
$string : string

The string to format

Return values
string

The formatted string

formatValue()

Format SQL value

public formatValue(mixed $value) : string
Parameters
$value : mixed

The value to format.

Return values
string

The formatted value.

Format the given value to the matching SQL type. If the value is a float, we make french decimal compatible with SQL. If null, we use the NULL value, else we consider it as a string value.

formatValueList()

Format a list of values

public formatValueList(array<string|int, mixed> $list) : string
Parameters
$list : array<string|int, mixed>
Return values
string

getConfig()

public getConfig() : array<string|int, mixed>
Return values
array<string|int, mixed>

getDriver()

Get the driven string

public static getDriver() : string
Return values
string

insert()

Insert something in database

public insert([array<string|int, mixed> $options = [] ]) : int
Parameters
$options : array<string|int, mixed> = []

The options used to build the query.

Tags
throws
Exception
Return values
int

The number of inserted rows.

It parses the query from an array to a INSERT query. Accept only the String syntax for what option.

lastId()

Get the last inserted ID It requires a successful call of insert() !

public lastId(string $table) : string|null
Parameters
$table : string

The table to get the last inserted id.

Return values
string|null

The last inserted id value.

listConfig()

List all instance's configuration

public static listConfig() : array<string|int, mixed>
Return values
array<string|int, mixed>

prepareQuery()

Prepare the query for the given instance

public static prepareQuery([array<string|int, mixed> &$options = [] ][, string|null &$instance = null ][, string|null $idField = null ]) : void
Parameters
$options : array<string|int, mixed> = []

The options used to build the query.

$instance : string|null = null

The db instance used to send the query.

$idField : string|null = null

The ID field of the table.

query()

Query the DB server

public query(string $query[, int $fetch = self::PROCESS_QUERY ]) : mixed
Parameters
$query : string

The query to execute.

$fetch : int = self::PROCESS_QUERY

See PDO constants above. Optional, default is PROCESS_QUERY.

Tags
see
pdo_query()
Return values
mixed

The result of pdo_query()

registerAdapter()

Register a driver adapter

public static registerAdapter(string $driver, string $class) : void
Parameters
$driver : string
$class : string

select()

Select data from tables in database

public select([array<string|int, mixed> $options = [] ]) : mixed
Parameters
$options : array<string|int, mixed> = []

The options used to build the query.

Tags
throws
Exception
see
http://dev.mysql.com/doc/refman/5.0/en/select.html
Return values
mixed

Mixed return, depending on the 'output' option.

setDefaultIdField()

Set the id field

public setDefaultIdField(string $field) : static
Parameters
$field : string

The new ID field.

Return values
static

update()

Update something in database Using pdo_query(), It parses the query from an array to a UPDATE query.

public update([array<string|int, mixed> $options = [] ]) : int
Parameters
$options : array<string|int, mixed> = []

The options used to build the query.

Tags
throws
Exception
see
http://dev.mysql.com/doc/refman/5.0/en/update.html
Return values
int

The number of affected rows.

connect()

Connect to the DBMS

protected connect() : void

executeRawQuery()

protected executeRawQuery(string $query, int $fetch) : mixed
Parameters
$query : string
$fetch : int

formatFieldList()

Format the given $fields into an escaped SQL string list of key=value

protected formatFieldList(array<string|int, mixed>|string $fields) : string
Parameters
$fields : array<string|int, mixed>|string
Return values
string

formatWhere()

protected formatWhere(mixed $where) : string
Parameters
$where : mixed
Return values
string

getDefaults()

Get defaults configuration to fill missing options

protected static getDefaults() : array<string|int, mixed>
Return values
array<string|int, mixed>

parseJoin()

Parse join option to generate join

protected parseJoin(mixed $options) : string
Parameters
$options : mixed
Return values
string

processPdoException()

protected processPdoException(PDOException $exception[, string|null $query = null ]) : void
Parameters
$exception : PDOException
$query : string|null = null

							
On this page

Search results