Orpheus

MsSqlAdapter extends AbstractSqlAdapter
in package

The MS Sql Adapter class

This class is the sql adapter for MSSQL.

Install method for debian: http://atutility.com/2007/09/14/install-pdo-pdo_sqlite-pdo_dblib-pdo_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|string
Select something from database
setDefaultIdField()  : static
Set the id field
startTransaction()  : AbstractSqlAdapter
update()  : int
Update something in database
connect()  : void
Connect to the DBMS
executeRawQuery()  : mixed
formatFieldList()  : string
Format the given $fields into an escaped SQL string list of key=value
getDefaults()  : array<string|int, mixed>
Get defaults configuration to fill missing options
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 'number_percent' => false, // false => No Percent option '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 'number_percent' => false, // false => No Percent option 'offset' => 0, //0 => The start 'output' => \Orpheus\SqlAdapter\AbstractSqlAdapter::RETURN_ARRAY_ASSOC, ]

$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 'number_percent' => false, // false => No Percent option '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

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

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

setDefaultIdField()

Set the id field

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

The new ID field.

Return values
static

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

getDefaults()

Get defaults configuration to fill missing options

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

processPdoException()

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

							
On this page

Search results