Constants

OBJECT

OBJECT

ARR_FIRST

ARR_FIRST

ARR_ASSOC

ARR_ASSOC

ARR_OBJECTS

ARR_OBJECTS

STATEMENT

STATEMENT

SQLQUERY

SQLQUERY

NUMBER

NUMBER

Properties

$IDFIELD

$IDFIELD : string

The ID field

Type

string

$pdo

$pdo : \PDO

The PDO instance

Type

\PDO

$selectDefaults

$selectDefaults : array

Select defaults options

Type

array

$updateDefaults

$updateDefaults : array

Update defaults options

Type

array

$deleteDefaults

$deleteDefaults : array

Delete defaults options

Type

array

$insertDefaults

$insertDefaults : array

Insert defaults options

Type

array

$instances

$instances : array

All Adapter instances by name

Type

array

$adapters

$adapters : array

Store drivers' adapter

Type

array

$configs

$configs : \Orpheus\SQLAdapter\unknown

Configurations

Type

\Orpheus\SQLAdapter\unknown

$lastID

$lastID : integer

Last ID

Type

integer

Methods

__construct()

__construct(string  $name, mixed  $config) 

Constructor

Parameters

string $name

The name of the instance

mixed $config

Instance config to use, maybe a config name, a config array or a PDO instance

getInstance()

getInstance(string  $name = null) : \Orpheus\SQLAdapter\SQLAdapter

Get an unique instance of SQLAdapter by its name

Parameters

string $name

Name of the instance, default value is "default"

Returns

\Orpheus\SQLAdapter\SQLAdapter

registerAdapter()

registerAdapter(string  $driver, string  $class) 

Register a driver adapter

Parameters

string $driver
string $class

make()

make(string  $name = 'default') : \Orpheus\SQLAdapter\SQLAdapter

Try to make a SQLAdapter by its name loading from configuration

Parameters

string $name

Throws

\Orpheus\SQLAdapter\Exception\SQLException

Returns

\Orpheus\SQLAdapter\SQLAdapter

listConfig()

listConfig() : array

List all instance's configuration

Returns

array

query()

query(  $Query,   $Fetch = PDOQUERY) : \Orpheus\SQLAdapter\The

Query the DB server

Parameters

$Query

The query to execute.

$Fetch

See PDO constants above. Optional, default is PDOQUERY.

Returns

\Orpheus\SQLAdapter\The —

result of pdo_query()

select()

select(array  $options = array()) : mixed

Select something from database

Parameters

array $options

The options used to build the query

Returns

mixed —

Mixed return, depending on the 'output' option

update()

update(array  $options = array()) : integer

Update something in database

Parameters

array $options

The options used to build the query

Returns

integer —

The number of affected rows

insert()

insert(array  $options = array()) : integer

Insert something in database

Parameters

array $options

The options used to build the query

Returns

integer —

The number of inserted rows

delete()

delete(array  $options = array()) : integer

Delete something in database

Parameters

array $options

The options used to build the query

Returns

integer —

The number of deleted rows

lastID()

lastID(string  $table) : \Orpheus\SQLAdapter\The

Get the last inserted ID

Parameters

string $table

The table to get the last inserted id

Returns

\Orpheus\SQLAdapter\The —

last inserted id value

It requires a successful call of insert() !

escapeIdentifier()

escapeIdentifier(string  $identifier) : string

Escape SQL identifiers

Parameters

string $identifier

The identifier to escape

Returns

string —

The escaped identifier

Escapes the given string as an SQL identifier.

formatString()

formatString(string  $str) : \Orpheus\SQLAdapter\The

Format SQL string

Parameters

string $str

The string to format.

Returns

\Orpheus\SQLAdapter\The —

formatted string.

Format the given string as an SQL string.

formatValue()

formatValue(string  $value) : \Orpheus\SQLAdapter\The

Format SQL value

Parameters

string $value

The value to format.

Returns

\Orpheus\SQLAdapter\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.

escapeValue()

escapeValue(string  $value) : \Orpheus\SQLAdapter\The

Escape SQL value

Parameters

string $value

The value to format.

Returns

\Orpheus\SQLAdapter\The —

formatted value.

formatValueList()

formatValueList(array  $list) : string

Format a list of values

Parameters

array $list

Returns

string

setIDField()

setIDField(string  $field) : \Orpheus\SQLAdapter\SQLAdapter

Set the IDFIELD

Parameters

string $field

The new ID field.

Returns

\Orpheus\SQLAdapter\SQLAdapter

Set the IDFIELD value to $field

doSelect()

doSelect(array  $options = array(), string  $instance = null, string  $IDField = null) 

The static function to use for SELECT queries in global context

Parameters

array $options

The options used to build the query.

string $instance

The db instance used to send the query.

string $IDField

The ID field of the table.

doUpdate()

doUpdate(  $options = array(),   $instance = null,   $IDField = null) 

The static function to use for UPDATE queries in global context

Parameters

$options

The options used to build the query.

$instance

The db instance used to send the query.

$IDField

The ID field of the table.

doDelete()

doDelete(  $options = array(),   $instance = null,   $IDField = null) 

The static function to use for DELETE queries in global context

Parameters

$options

The options used to build the query.

$instance

The db instance used to send the query.

$IDField

The ID field of the table.

doInsert()

doInsert(  $options = array(),   $instance = null,   $IDField = null) 

The static function to use for INSERT queries in global context

Parameters

$options

The options used to build the query.

$instance

The db instance used to send the query.

$IDField

The ID field of the table.

doLastID()

doLastID(  $table,   $IDField = 'id',   $instance = null) 

The static function to use to get last isnert id in global context

Parameters

$table

The table to get the last ID. Some DBMS ignore it.

$IDField

The field id name.

$instance

The db instance used to send the query.

doEscapeIdentifier()

doEscapeIdentifier(  $Identifier,   $instance = null) : \Orpheus\SQLAdapter\The

Escapes SQL identifiers

Parameters

$Identifier

The identifier to escape.

$instance

The db instance used to send the query.

Returns

\Orpheus\SQLAdapter\The —

escaped identifier.

doFormatString()

doFormatString(  $String,   $instance = null) : \Orpheus\SQLAdapter\The

Escapes SQL identifiers

Parameters

$String

The value to format.

$instance

The db instance used to send the query.

Returns

\Orpheus\SQLAdapter\The —

formatted value.

doFormatValue()

doFormatValue(string  $value,   $instance = null) : \Orpheus\SQLAdapter\The

The static function to quote

Parameters

string $value

The string to quote.

$instance

The db instance used to send the query.

Returns

\Orpheus\SQLAdapter\The —

quoted string.

prepareQuery()

prepareQuery(  $options = array(),   $instance = null,   $IDField = null) 

Prepare the query for the given instance

Parameters

$options

The options used to build the query.

$instance

The db instance used to send the query.

$IDField

The ID field of the table.

prepareInstance()

prepareInstance(  $instance = null) 

The static function to prepareInstance an adapter for the given instance

Parameters

$instance

The db instance name to prepareInstance.

registerInstance()

registerInstance(string  $name, \Orpheus\SQLAdapter\SQLAdapter  $adapter) 

Register an unique instance by its name

Parameters

string $name
\Orpheus\SQLAdapter\SQLAdapter $adapter

getDefaults()

getDefaults() : array<mixed,string>

Get defaults configuration to fill missing options

Returns

array<mixed,string>

connect()

connect(array  $config) 

Connect to the DBMS using $config

Parameters

array $config

formatFieldList()

formatFieldList(array|string  $fields) : string

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

Parameters

array|string $fields

Returns

string