Documentation

SeedDMS_Core_DatabaseAccess
in package

Class to represent the database access for the document management This class uses PDO for the actual database access.

Tags
category

DMS

author

Uwe Steinmann uwe@steinmann.cx

copyright

Copyright (C) 2012 Uwe Steinmann

version

Release: @package_version@

Table of Contents

Properties

$_debug  : bool
$_database  : string
$_driver  : string
$_hostname  : string
$_passw  : string
$_port  : int
$_user  : string
$_conn  : object
$_connected  : bool
$_intransaction  : bool
$_logfile  : string
$_logfp  : resource
$_ttapproveid  : bool
$_ttcontentid  : bool
$_ttreceiptid  : bool
$_ttreviewid  : bool
$_ttrevisionid  : bool
$_ttstatid  : bool
$_useviews  : bool

Methods

__construct()  : mixed
Constructor of SeedDMS_Core_DatabaseAccess
__destruct()  : mixed
Destructor of SeedDMS_Core_DatabaseAccess
castToText()  : string
Return sql statement for returning the current timestamp
commitTransaction()  : mixed
concat()  : string
Return sql to concat strings or fields
connect()  : bool
Connect to database
createDump()  : bool
Create an sql dump of the complete database
createTemporaryTable()  : bool
Create various temporary tables or view to speed up and simplify sql queries
dropTemporaryTable()  : bool
Drop various temporary tables to force recreation when next time needed
ensureConnected()  : bool
Make sure a database connection exisits
getCurrentDatetime()  : string
Return sql statement for returning the current date and time in format Y-m-d H:i:s
getCurrentTimestamp()  : string
Return sql statement for returning the current timestamp
getDateExtract()  : string
Return sql statement for extracting the date part from a field containing a unix timestamp
getDriver()  : string
Return driver
getErrorMsg()  : mixed
getErrorNo()  : mixed
getInsertID()  : int
Return the id of the last instert record
getResult()  : bool
Execute SQL query
getResultArray()  : array<string|int, mixed>|bool
Execute SQL query and return result
hasTable()  : bool
Check if database has a table
inTransaction()  : mixed
qstr()  : string
Sanitize String used in database operations
rbt()  : string
Replace back ticks by '"'
rollbackTransaction()  : mixed
setLogFp()  : mixed
Set the file pointer to a log file
startTransaction()  : mixed
TableList()  : array<string|int, string>|bool
Return list of all database tables
useViews()  : mixed
Turn on views instead of temp. tables
ViewList()  : array<string|int, mixed>
Return list of all database views
__createTemporaryTable()  : bool
Create various temporary tables to speed up and simplify sql queries
__createView()  : bool
Create various views to speed up and simplify sql queries
__dropTemporaryTable()  : bool
Drop various temporary tables to enforce recreation when needed

Properties

$_driver

protected string $_driver

name of database driver (mysql or sqlite)

$_connected

private bool $_connected

set to true if connection to database is established

$_intransaction

private bool $_intransaction

set to true if in a database transaction

$_logfile

private string $_logfile

set a valid file name for logging all sql queries

$_ttapproveid

private bool $_ttapproveid

set to true if temp. table for approvals has been created

$_ttcontentid

private bool $_ttcontentid

set to true if temp. table for doc content has been created

$_ttreceiptid

private bool $_ttreceiptid

set to true if temp. table for doc reception has been created

$_ttreviewid

private bool $_ttreviewid

set to true if temp. table for tree view has been created

$_ttrevisionid

private bool $_ttrevisionid

set to true if temp. table for doc revision has been created

$_ttstatid

private bool $_ttstatid

set to true if temp. table for doc status has been created

$_useviews

private bool $_useviews

set to true if views instead of temp. tables shall be used

Methods

__construct()

Constructor of SeedDMS_Core_DatabaseAccess

public __construct(string $driver, string $hostname, string $user, string $passw[, bool|string $database = false ]) : mixed

Sets all database parameters but does not connect.

Parameters
$driver : string

the database type e.g. mysql, sqlite

$hostname : string

host of database server

$user : string

name of user having access to database

$passw : string

password of user

$database : bool|string = false

name of database

__destruct()

Destructor of SeedDMS_Core_DatabaseAccess

public __destruct() : mixed

castToText()

Return sql statement for returning the current timestamp

public castToText( $field) : string
Parameters
$field :
Return values
string

sql code

concat()

Return sql to concat strings or fields

public concat(array<string|int, mixed> $arr) : string
Parameters
$arr : array<string|int, mixed>

list of field names or strings

Return values
string

concated string

connect()

Connect to database

public connect() : bool
Return values
bool

true if connection could be established, otherwise false

createDump()

Create an sql dump of the complete database

public createDump(resource $fp) : bool
Parameters
$fp : resource

name of dump file

Return values
bool

createTemporaryTable()

Create various temporary tables or view to speed up and simplify sql queries

public createTemporaryTable(string $tableName[, bool $override = false ]) : bool
Parameters
$tableName : string
$override : bool = false
Return values
bool

dropTemporaryTable()

Drop various temporary tables to force recreation when next time needed

public dropTemporaryTable(string $tableName) : bool
Parameters
$tableName : string
Return values
bool

ensureConnected()

Make sure a database connection exisits

public ensureConnected() : bool

This function checks for a database connection. If it does not exists it will reconnect.

Return values
bool

true if connection is established, otherwise false

getCurrentDatetime()

Return sql statement for returning the current date and time in format Y-m-d H:i:s

public getCurrentDatetime([mixed $dayoffset = 0 ]) : string
Parameters
$dayoffset : mixed = 0
Return values
string

sql code

getCurrentTimestamp()

Return sql statement for returning the current timestamp

public getCurrentTimestamp() : string
Return values
string

sql code

getDateExtract()

Return sql statement for extracting the date part from a field containing a unix timestamp

public getDateExtract(string $fieldname[, string $format = '%Y-%m-%d' ]) : string
Parameters
$fieldname : string

name of field containing the timestamp

$format : string = '%Y-%m-%d'
Return values
string

sql code

getDriver()

Return driver

public getDriver() : string
Return values
string

name of driver as set in constructor

getInsertID()

Return the id of the last instert record

public getInsertID([string $tablename = '' ][, string $fieldname = 'id' ]) : int
Parameters
$tablename : string = ''
$fieldname : string = 'id'
Return values
int

id used in last autoincrement

getResult()

Execute SQL query

public getResult(string $queryStr[, bool $retick = true ]) : bool

Call this function only with sql query which do not return data records.

Parameters
$queryStr : string

sql query

$retick : bool = true

replace all '`' by '"'

Return values
bool

true if query could be executed otherwise false

getResultArray()

Execute SQL query and return result

public getResultArray(string $queryStr[, bool $retick = true ]) : array<string|int, mixed>|bool

Call this function only with sql query which return data records.

Parameters
$queryStr : string

sql query

$retick : bool = true
Return values
array<string|int, mixed>|bool

data if query could be executed otherwise false

hasTable()

Check if database has a table

public hasTable(mixed $name) : bool

This function will check if the database has a table with the given table name

Parameters
$name : mixed
Return values
bool

true if table exists, otherwise false

qstr()

Sanitize String used in database operations

public qstr(string $text) : string
Parameters
$text : string
Return values
string

sanitized string

rbt()

Replace back ticks by '"'

public rbt(string $text) : string
Parameters
$text : string
Return values
string

sanitized string

setLogFp()

Set the file pointer to a log file

public setLogFp(mixed $fp) : mixed

Once it is set, all queries will be logged into this file

Parameters
$fp : mixed

TableList()

Return list of all database tables

public TableList() : array<string|int, string>|bool

This function is used to retrieve a list of database tables for backup

Return values
array<string|int, string>|bool

list of table names

useViews()

Turn on views instead of temp. tables

public useViews(bool $onoff) : mixed
Parameters
$onoff : bool

turn use of views instead of temp. table on/off

ViewList()

Return list of all database views

public ViewList() : array<string|int, mixed>

This function is used to retrieve a list of database views

Return values
array<string|int, mixed>

list of view names

__createTemporaryTable()

Create various temporary tables to speed up and simplify sql queries

private __createTemporaryTable(string $tableName[, bool $override = false ]) : bool
Parameters
$tableName : string
$override : bool = false
Return values
bool

__createView()

Create various views to speed up and simplify sql queries

private __createView(string $tableName[, bool $override = false ]) : bool
Parameters
$tableName : string
$override : bool = false
Return values
bool

__dropTemporaryTable()

Drop various temporary tables to enforce recreation when needed

private __dropTemporaryTable(string $tableName) : bool
Parameters
$tableName : string
Return values
bool

        
On this page

Search results