sqlsrvDbConnection
extends jDbConnection
in package
Tags
Table of Contents
- ATTR_AUTOCOMMIT = 0
- ATTR_CASE = 8
- ATTR_CLIENT_VERSION = 5
- ATTR_CONNECTION_STATUS = 7
- ATTR_CURSOR = 10
- ATTR_DRIVER_NAME = 16
- ATTR_ERRMODE = 3
- ATTR_ORACLE_NULLS = 11
- ATTR_PERSISTENT = 12
- ATTR_PREFETCH = 1
- ATTR_SERVER_INFO = 6
- ATTR_SERVER_VERSION = 4
- ATTR_TIMEOUT = 2
- CURSOR_FWDONLY = 0
- CURSOR_SCROLL = 1
- FETCH_CLASS = 8
- FETCH_INTO = 9
- FETCH_OBJ = 5
- $dbms : string
- The database type name (mysql, pgsql ...) It is not the driver name. Several drivers could connect to the same database type. This type name is often used to know whish SQL language we should use.
- $driverName : string
- driver name.
- $lastQuery : mixed
- last executed query.
- $msgError : string
- The last error message if any.
- $profile : array<string|int, mixed>
- profile properties used by the connector.
- $_connection : mixed
- the internal connection.
- $_debugMode : mixed
- $_schema : jDbSchema
- $foundParameters : mixed
- $numericalMarker : mixed
- $parameterMarker : mixed
- $_autocommit : bool
- Are we using an automatic commit ?
- __construct() : mixed
- Default constructor.
- __destruct() : mixed
- beginTransaction() : mixed
- begin a transaction.
- close() : mixed
- commit() : mixed
- Commit since the last begin.
- disconnect() : mixed
- alias of close().
- encloseName() : string
- enclose the field name.
- errorCode() : int
- errorInfo() : string
- exec() : int
- Launch a SQL Query (update, delete..) which doesn't return rows.
- getAttribute() : string
- getProfileName() : mixed
- hasTablePrefix() : bool
- Check if the current connection has a table prefix set.
- isClosed() : bool
- lastIdInTable() : int
- return the maximum value of the given primary key in a table.
- lastInsertId() : int
- return the id value of the last inserted row.
- limitQuery() : bool|jDbResultSet
- Launch a SQL Query with limit parameter, so it returns only a subset of a result.
- prefixTable() : string
- Prefix the given table with the prefix specified in the connection's profile If there's no prefix for the connection's profile, return the table's name unchanged.
- prepare() : jDbResultSet
- prepare a query. It may contain some named parameters declared as ':a_name' in the query.
- query() : bool|jDbResultSet
- Launch a SQL Query which returns rows (typically, a SELECT statement).
- quote() : string
- Escape and quotes strings.
- quote2() : string
- Escape and quotes strings. if null, will only return the text "NULL".
- rollback() : mixed
- Rollback since the last BEGIN.
- schema() : jDbSchema
- setAttribute() : mixed
- setAutoCommit() : mixed
- sets the autocommit state.
- tools() : jDbTools
- unprefixTable() : string
- Remove the prefix of the given table name.
- _autoCommitNotify() : mixed
- tell sqlsrv to be implicit commit or not.
- _connect() : int
- return a connection identifier or false/null if there is an error.
- _disconnect() : mixed
- do a disconnection (no need to do a test on the connection id).
- _doExec() : bool|jDbResultSet
- do a query which return nothing.
- _doLimitQuery() : bool|jDbResultSet
- do a query which return a limited number of results.
- _doQuery() : bool|jDbResultSet
- do a query which return results.
- _getErrorMsg() : mixed
- _quote() : string
- escape special characters.
- _replaceParam() : mixed
- findParameters() : array<string|int, mixed>
- replace named parameters into the given query, by the given marker, for db API that don't support named parameters for prepared queries.
Constants
ATTR_AUTOCOMMIT
public
mixed
ATTR_AUTOCOMMIT
= 0
Tags
ATTR_CASE
public
mixed
ATTR_CASE
= 8
Tags
ATTR_CLIENT_VERSION
public
mixed
ATTR_CLIENT_VERSION
= 5
Tags
ATTR_CONNECTION_STATUS
public
mixed
ATTR_CONNECTION_STATUS
= 7
Tags
ATTR_CURSOR
public
mixed
ATTR_CURSOR
= 10
Tags
ATTR_DRIVER_NAME
public
mixed
ATTR_DRIVER_NAME
= 16
Tags
ATTR_ERRMODE
public
mixed
ATTR_ERRMODE
= 3
Tags
ATTR_ORACLE_NULLS
public
mixed
ATTR_ORACLE_NULLS
= 11
Tags
ATTR_PERSISTENT
public
mixed
ATTR_PERSISTENT
= 12
Tags
ATTR_PREFETCH
public
mixed
ATTR_PREFETCH
= 1
Tags
ATTR_SERVER_INFO
public
mixed
ATTR_SERVER_INFO
= 6
Tags
ATTR_SERVER_VERSION
public
mixed
ATTR_SERVER_VERSION
= 4
Tags
ATTR_TIMEOUT
public
mixed
ATTR_TIMEOUT
= 2
Tags
CURSOR_FWDONLY
public
mixed
CURSOR_FWDONLY
= 0
Tags
CURSOR_SCROLL
public
mixed
CURSOR_SCROLL
= 1
Tags
FETCH_CLASS
public
mixed
FETCH_CLASS
= 8
Tags
FETCH_INTO
public
mixed
FETCH_INTO
= 9
Tags
FETCH_OBJ
public
mixed
FETCH_OBJ
= 5
Tags
Properties
$dbms
The database type name (mysql, pgsql ...) It is not the driver name. Several drivers could connect to the same database type. This type name is often used to know whish SQL language we should use.
public
string
$dbms
Tags
$driverName
driver name.
public
string
$driverName
= ''
Tags
$lastQuery
last executed query.
public
mixed
$lastQuery
Tags
$msgError
The last error message if any.
public
string
$msgError
= ''
Tags
$profile
profile properties used by the connector.
public
array<string|int, mixed>
$profile
Tags
$_connection
the internal connection.
protected
mixed
$_connection
Tags
$_debugMode
protected
mixed
$_debugMode
= \false
Tags
$_schema
protected
jDbSchema
$_schema
Tags
$foundParameters
protected
mixed
$foundParameters
= array()
Tags
$numericalMarker
protected
mixed
$numericalMarker
= \false
Tags
$parameterMarker
protected
mixed
$parameterMarker
= '?'
Tags
$_autocommit
Are we using an automatic commit ?
private
bool
$_autocommit
= \true
Tags
Methods
__construct()
Default constructor.
public
__construct(array<string|int, mixed> $profile) : mixed
Parameters
- $profile : array<string|int, mixed>
-
profile de connexion
Tags
Return values
mixed —__destruct()
public
__destruct() : mixed
Tags
Return values
mixed —beginTransaction()
begin a transaction.
public
beginTransaction() : mixed
Tags
Return values
mixed —close()
public
close() : mixed
Tags
Return values
mixed —commit()
Commit since the last begin.
public
commit() : mixed
Tags
Return values
mixed —disconnect()
alias of close().
public
disconnect() : mixed
Tags
Return values
mixed —encloseName()
enclose the field name.
public
encloseName(mixed $fieldName) : string
Parameters
- $fieldName : mixed
-
the field name
Tags
Return values
string —the enclosed field name
errorCode()
public
errorCode() : int
Tags
Return values
int —the last error code
errorInfo()
public
errorInfo() : string
Tags
Return values
string —the last error description
exec()
Launch a SQL Query (update, delete..) which doesn't return rows.
public
exec(string $query) : int
Parameters
- $query : string
-
the SQL query
Tags
Return values
int —the number of affected rows. False if the query has failed.
getAttribute()
public
getAttribute(int $id) : string
Parameters
- $id : int
-
the attribut id
Tags
Return values
string —the attribute value
getProfileName()
public
getProfileName() : mixed
Tags
Return values
mixed —hasTablePrefix()
Check if the current connection has a table prefix set.
public
hasTablePrefix() : bool
Tags
Return values
bool —isClosed()
public
isClosed() : bool
Tags
Return values
bool —lastIdInTable()
return the maximum value of the given primary key in a table.
public
lastIdInTable(string $fieldName, string $tableName) : int
Parameters
- $fieldName : string
-
the name of the primary key
- $tableName : string
-
the name of the table
Tags
Return values
int —the maximum value
lastInsertId()
return the id value of the last inserted row.
public
lastInsertId([mixed $fromSequence = '' ]) : int
Parameters
- $fromSequence : mixed = ''
Tags
Return values
int —the last inserted ID incremented in database
limitQuery()
Launch a SQL Query with limit parameter, so it returns only a subset of a result.
public
limitQuery(string $queryString, int $limitOffset, int $limitCount) : bool|jDbResultSet
Parameters
- $queryString : string
-
the SQL query
- $limitOffset : int
-
the offset of the first row to return
- $limitCount : int
-
the maximum of number of rows to return
Tags
Return values
bool|jDbResultSet —SQL Select. False if the query has failed.
prefixTable()
Prefix the given table with the prefix specified in the connection's profile If there's no prefix for the connection's profile, return the table's name unchanged.
public
prefixTable(mixed $table_name) : string
Parameters
- $table_name : mixed
Tags
Return values
string —the prefixed table's name
prepare()
prepare a query. It may contain some named parameters declared as ':a_name' in the query.
public
prepare(mixed $query) : jDbResultSet
Parameters
- $query : mixed
Tags
Return values
jDbResultSet —a statement with which you can bind values or variables to named parameters, and execute the statement
query()
Launch a SQL Query which returns rows (typically, a SELECT statement).
public
query(string $queryString[, int $fetchmode = self::FETCH_OBJ ][, null|mixed $arg1 = null ][, array<string|int, mixed> $ctoargs = null ]) : bool|jDbResultSet
Parameters
- $queryString : string
-
the SQL query
- $fetchmode : int = self::FETCH_OBJ
-
FETCH_OBJ, FETCH_CLASS or FETCH_INTO
- $arg1 : null|mixed = null
- $ctoargs : array<string|int, mixed> = null
-
arguments for the constructor if FETCH_CLASS
Tags
Return values
bool|jDbResultSet —false if the query has failed
quote()
Escape and quotes strings.
public
quote(string $text, int $parameter_type) : string
Parameters
- $text : string
-
string to quote
- $parameter_type : int
-
unused, just for compatibility with PDO
Tags
Return values
string —escaped string
quote2()
Escape and quotes strings. if null, will only return the text "NULL".
public
quote2(string $text[, bool $checknull = true ][, bool $binary = false ]) : string
Parameters
- $text : string
-
string to quote
- $checknull : bool = true
-
if true, check if $text is a null value, and then return NULL
- $binary : bool = false
-
set to true if $text contains a binary string
Tags
Return values
string —escaped string
rollback()
Rollback since the last BEGIN.
public
rollback() : mixed
Tags
Return values
mixed —schema()
public
schema() : jDbSchema
Tags
Return values
jDbSchema —setAttribute()
public
setAttribute(int $id, string $value) : mixed
Parameters
- $id : int
-
the attribut id
- $value : string
-
the attribute value
Tags
Return values
mixed —setAutoCommit()
sets the autocommit state.
public
setAutoCommit([bool $state = true ]) : mixed
Parameters
- $state : bool = true
-
the status of autocommit
Tags
Return values
mixed —tools()
public
tools() : jDbTools
Tags
Return values
jDbTools —unprefixTable()
Remove the prefix of the given table name.
public
unprefixTable(string $tableName) : string
Parameters
- $tableName : string
Tags
Return values
string —the table name unprefixed
_autoCommitNotify()
tell sqlsrv to be implicit commit or not.
protected
_autoCommitNotify(bool $state) : mixed
Parameters
- $state : bool
-
the state of the autocommit value
@see https://docs.microsoft.com/en-us/sql/t-sql/statements/set-implicit-transactions-transact-sql?view=sql-server-ver15
Tags
Return values
mixed —_connect()
return a connection identifier or false/null if there is an error.
protected
_connect() : int
Tags
Return values
int —connection identifier
_disconnect()
do a disconnection (no need to do a test on the connection id).
protected
_disconnect() : mixed
Tags
Return values
mixed —_doExec()
do a query which return nothing.
protected
_doExec(mixed $query) : bool|jDbResultSet
Parameters
- $query : mixed
Tags
Return values
bool|jDbResultSet —_doLimitQuery()
do a query which return a limited number of results.
protected
_doLimitQuery(mixed $queryString, mixed $offset, mixed $number) : bool|jDbResultSet
Parameters
- $queryString : mixed
- $offset : mixed
- $number : mixed
Tags
Return values
bool|jDbResultSet —_doQuery()
do a query which return results.
protected
_doQuery(mixed $query) : bool|jDbResultSet
Parameters
- $query : mixed
Tags
Return values
bool|jDbResultSet —_getErrorMsg()
protected
_getErrorMsg() : mixed
Tags
Return values
mixed —_quote()
escape special characters.
protected
_quote(mixed $text, mixed $binary) : string
Parameters
- $text : mixed
- $binary : mixed
Tags
Return values
string —the escaped string
_replaceParam()
protected
_replaceParam(mixed $matches) : mixed
Parameters
- $matches : mixed
Tags
Return values
mixed —findParameters()
replace named parameters into the given query, by the given marker, for db API that don't support named parameters for prepared queries.
protected
findParameters(string $sql, string $marker) : array<string|int, mixed>
Parameters
- $sql : string
- $marker : string
-
a string which will replace each named parameter in the query. it may end by a '%' so named parameters are replaced by numerical parameter. ex : '$%' : named parameters will be replaced by $1, $2, $3...
Tags
Return values
array<string|int, mixed> —0:the new sql, 1: list of parameters names, in the order they appear into the query