Menu

## SeedDMS_Core_DatabaseAccess
in package

inc.DBAccessPDO.php : 27

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
$_ttreviewid : 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

#### $_debug

inc.DBAccessPDO.php : 31
`public bool $_debug`

set to true for debug mode

#### $_database

inc.DBAccessPDO.php : 51
`protected string $_database`

name of database

#### $_driver

inc.DBAccessPDO.php : 36
`protected string $_driver`

name of database driver (mysql or sqlite)

#### $_hostname

inc.DBAccessPDO.php : 41
`protected string $_hostname`

name of hostname

#### $_passw

inc.DBAccessPDO.php : 61
`protected string $_passw`

password of database user

#### $_port

inc.DBAccessPDO.php : 46
`protected int $_port`

port number of database

#### $_user

inc.DBAccessPDO.php : 56
`protected string $_user`

name of database user

#### $_conn

inc.DBAccessPDO.php : 66
`private object $_conn`

internal database connection

#### $_connected

inc.DBAccessPDO.php : 71
`private bool $_connected`

set to true if connection to database is established

#### $_intransaction

inc.DBAccessPDO.php : 96
`private bool $_intransaction`

set to true if in a database transaction

#### $_logfile

inc.DBAccessPDO.php : 101
`private string $_logfile`

set a valid file name for logging all sql queries

#### $_logfp

inc.DBAccessPDO.php : 106
`private resource $_logfp`

file pointer of log file

#### $_ttapproveid

inc.DBAccessPDO.php : 81
`private bool $_ttapproveid`

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

#### $_ttcontentid

inc.DBAccessPDO.php : 91
`private bool $_ttcontentid`

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

#### $_ttreviewid

inc.DBAccessPDO.php : 76
`private bool $_ttreviewid`

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

#### $_ttstatid

inc.DBAccessPDO.php : 86
`private bool $_ttstatid`

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

#### $_useviews

inc.DBAccessPDO.php : 111
`private bool $_useviews`

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

### Methods

#### __construct()

inc.DBAccessPDO.php : 207

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

inc.DBAccessPDO.php : 263

Destructor of SeedDMS_Core_DatabaseAccess

`public __destruct() : mixed`

#### castToText()

inc.DBAccessPDO.php : 1016

Return sql statement for returning the current timestamp

`public castToText( $field) : string`

##### Parameters

$field :

##### Return values

string —

sql code

#### commitTransaction()

inc.DBAccessPDO.php : 474
`public commitTransaction() : mixed`

#### concat()

inc.DBAccessPDO.php : 377

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

inc.DBAccessPDO.php : 284

Connect to database

`public connect() : bool`

##### Return values

bool —

true if connection could be established, otherwise false

#### createDump()

inc.DBAccessPDO.php : 1031

Create an sql dump of the complete database

`public createDump(resource $fp) : bool`

##### Parameters

$fp : resource

  name of dump file

##### Return values

bool

#### createTemporaryTable()

inc.DBAccessPDO.php : 909

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

inc.DBAccessPDO.php : 923

Drop various temporary tables to force recreation when next time needed

`public dropTemporaryTable(string $tableName) : bool`

##### Parameters

$tableName : string

##### Return values

bool

#### ensureConnected()

inc.DBAccessPDO.php : 346

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

inc.DBAccessPDO.php : 966

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

`public getCurrentDatetime([mixed $offset = 0 ]) : string`

##### Parameters

$offset : mixed = 0

##### Return values

string —

sql code

#### getCurrentTimestamp()

inc.DBAccessPDO.php : 995

Return sql statement for returning the current timestamp

`public getCurrentTimestamp() : string`

##### Return values

string —

sql code

#### getDateExtract()

inc.DBAccessPDO.php : 938

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

inc.DBAccessPDO.php : 247

Return driver

`public getDriver() : string`

##### Return values

string —

name of driver as set in constructor

#### getErrorMsg()

inc.DBAccessPDO.php : 502
`public getErrorMsg() : mixed`

#### getErrorNo()

inc.DBAccessPDO.php : 507
`public getErrorNo() : mixed`

#### getInsertID()

inc.DBAccessPDO.php : 495

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

inc.DBAccessPDO.php : 433

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

inc.DBAccessPDO.php : 401

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

inc.DBAccessPDO.php : 148

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

#### inTransaction()

inc.DBAccessPDO.php : 484
`public inTransaction() : mixed`

#### qstr()

inc.DBAccessPDO.php : 357

Sanitize String used in database operations

`public qstr(string $text) : string`

##### Parameters

$text : string

##### Return values

string —

sanitized string

#### rbt()

inc.DBAccessPDO.php : 367

Replace back ticks by '"'

`public rbt(string $text) : string`

##### Parameters

$text : string

##### Return values

string —

sanitized string

#### rollbackTransaction()

inc.DBAccessPDO.php : 464
`public rollbackTransaction() : mixed`

#### setLogFp()

inc.DBAccessPDO.php : 275

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

#### startTransaction()

inc.DBAccessPDO.php : 454
`public startTransaction() : mixed`

#### TableList()

inc.DBAccessPDO.php : 120

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

inc.DBAccessPDO.php : 256

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

inc.DBAccessPDO.php : 175

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

inc.DBAccessPDO.php : 518

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

inc.DBAccessPDO.php : 742

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

inc.DBAccessPDO.php : 708

Drop various temporary tables to enforce recreation when needed

`private __dropTemporaryTable(string $tableName) : bool`

##### Parameters

$tableName : string

##### Return values

bool

## Search results