jDbConnection

package

jelix

subpackage

db

Methods

do a connection to the database, using properties of the given profile

__construct(array $profile) 

Arguments

$profile

array

profile properties

__destruct

__destruct() 

Notify the changes on autocommit Drivers may overload this

_autoCommitNotify(boolean $state) 
abstract

Arguments

$state

boolean

the new state of autocommit

return a connection identifier or false/null if there is an error

_connect() : integer
abstract

Response

integer

connection identifier

do a disconnection (no need to do a test on the connection id)

_disconnect() 
abstract

do a query which return nothing

_doExec( $queryString) : \jDbResultSet/boolean
abstract

Arguments

$queryString

Response

\jDbResultSet/boolean

do a query which return a limited number of results

_doLimitQuery( $queryString,  $offset,  $number) : \jDbResultSet/boolean
abstract

Arguments

$queryString

$offset

$number

Response

\jDbResultSet/boolean

do a query which return results

_doQuery( $queryString) : \jDbResultSet/boolean
abstract

Arguments

$queryString

Response

\jDbResultSet/boolean

do the escaping of a string.

_quote(string $text, boolean $binary) : string

you should override it into the driver

Arguments

$text

string

the text to escape

$binary

boolean

true if the content of the string is a binary content

Response

string

the escaped string

_replaceParam

_replaceParam( $matches) 

Arguments

$matches

begin a transaction. Call it before query, limitQuery, exec And then commit() or rollback()

beginTransaction() 
abstract

validate all queries and close a transaction

commit() 
abstract

disconnect

disconnect() 

enclose the field name

encloseName(string $fieldName) : string
since 1.1.1

Arguments

$fieldName

string

the field name

Response

string

the enclosed field name

errorCode

errorCode() : integer
abstract

Response

integer

the last error code

errorInfo

errorInfo() : string
abstract

Response

string

the last error description

Launch a SQL Query (update, delete.

exec(string $query) : integer

.) which doesn't return rows

Arguments

$query

string

the SQL query

Response

integer

the number of affected rows. False if the query has failed.

replace named parameters into the given query, by the given marker, for db API that don't support named parameters for prepared queries.

findParameters(string $sql, string $marker) : array

Arguments

$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...

Response

array

0:the new sql, 1: list of parameters names, in the order they appear into the query

getAttribute

getAttribute(integer $id) : string
abstract
see \PDO::getAttribute()

Arguments

$id

integer

the attribut id

Response

string

the attribute value

Check if the current connection has a table prefix set

hasTablePrefix() : boolean
author

Julien Issler

since 1.0

Response

boolean

return the maximum value of the given primary key in a table

lastIdInTable(string $fieldName, string $tableName) : integer

Arguments

$fieldName

string

the name of the primary key

$tableName

string

the name of the table

Response

integer

the maximum value

return the id value of the last inserted row.

lastInsertId(string $fromSequence = '') : integer
abstract

Some driver need a sequence name, so give it at first parameter

Arguments

$fromSequence

string

the sequence name

Response

integer

the id value

Launch a SQL Query with limit parameter, so it returns only a subset of a result

limitQuery(string $queryString, integer $limitOffset, integer $limitCount) : \jDbResultSet|boolean

Arguments

$queryString

string

the SQL query

$limitOffset

integer

the offset of the first row to return

$limitCount

integer

the maximum of number of rows to return

Response

\jDbResultSet|boolean

SQL Select. False if the query has failed.

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.

prefixTable( $table_name) : string
author

Julien Issler

since 1.0

Arguments

$table_name

Response

string

the prefixed table's name

prepare a query

prepare(string $query) : \statement
abstract

Arguments

$query

string

a sql query with parameters

Response

\statement

a statement

Launch a SQL Query which returns rows (typically, a SELECT statement)

query(string $queryString, integer $fetchmode = self::FETCH_OBJ,  $arg1 = null, array $ctoargs = null) : \jDbResultSet|boolean

Arguments

$queryString

string

the SQL query

$fetchmode

integer

FETCH_OBJ, FETCH_CLASS or FETCH_INTO

$arg1

$ctoargs

array

arguments for the constructor if FETCH_CLASS

Response

\jDbResultSet|boolean

False if the query has failed.

Escape and quotes strings.

quote(string $text, integer $parameter_type) : string

Arguments

$text

string

string to quote

$parameter_type

integer

unused, just for compatibility with PDO

Response

string

escaped string

Escape and quotes strings. if null, will only return the text "NULL"

quote2(string $text, boolean $checknull = true, boolean $binary = false) : string
since 1.2

Arguments

$text

string

string to quote

$checknull

boolean

if true, check if $text is a null value, and then return NULL

$binary

boolean

set to true if $text contains a binary string

Response

string

escaped string

cancel all queries of a transaction and close the transaction

rollback() 
abstract

schema

schema() : \jDbSchema
since 1.2

Response

\jDbSchema

setAttribute

setAttribute(integer $id, string $value) 
abstract
see \PDO::setAttribute()

Arguments

$id

integer

the attribut id

$value

string

the attribute value

sets the autocommit state

setAutoCommit(boolean $state = true) 

Arguments

$state

boolean

the status of autocommit

tools

tools() : \jDbTools
since 1.2

Response

\jDbTools

Remove the prefix of the given table name

unprefixTable(string $tableName) : string
since 1.6.16

Arguments

$tableName

string

Response

string

the table name unprefixed

Constants

FETCH_OBJ

FETCH_OBJ

FETCH_CLASS

FETCH_CLASS

FETCH_INTO

FETCH_INTO

ATTR_AUTOCOMMIT

ATTR_AUTOCOMMIT

ATTR_PREFETCH

ATTR_PREFETCH

ATTR_TIMEOUT

ATTR_TIMEOUT

ATTR_ERRMODE

ATTR_ERRMODE

ATTR_SERVER_VERSION

ATTR_SERVER_VERSION

ATTR_SERVER_INFO

ATTR_SERVER_INFO

ATTR_CLIENT_VERSION

ATTR_CLIENT_VERSION

ATTR_CONNECTION_STATUS

ATTR_CONNECTION_STATUS

ATTR_CASE

ATTR_CASE

ATTR_CURSOR

ATTR_CURSOR

ATTR_ORACLE_NULLS

ATTR_ORACLE_NULLS

ATTR_PERSISTENT

ATTR_PERSISTENT

ATTR_DRIVER_NAME

ATTR_DRIVER_NAME

CURSOR_FWDONLY

CURSOR_FWDONLY

CURSOR_SCROLL

CURSOR_SCROLL

Properties

profile properties used by the connector

profile : array
var

Type(s)

array

The database type name (mysql, pgsql .

dbms : string

..) 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.

var

Type(s)

string

driver name

driverName : string
var

Type(s)

string

The last error message if any

msgError : string
var

Type(s)

string

last executed query

lastQuery : 

Type(s)

Are we using an automatic commit ?

_autocommit : boolean
var

Type(s)

boolean

the internal connection.

_connection : mixed
var

Type(s)

mixed

_debugMode

_debugMode : 

Type(s)

_tools

_tools : \jDbTools
var
since

Type(s)

\jDbTools

_schema

_schema : \jDbSchema
var
since

Type(s)

\jDbSchema