Documentation

database
in package

FanPress CM Database abstraction layer

Tags
author

Stefan Seehafer sea75300@yahoo.de

copyright

(c) 2011-2020, Stefan Seehafer

Table of Contents

DBTYPE_MYSQLMARIADB  = 'mysql'
Datenbank-TypKonstante MySQL
DBTYPE_POSTGRES  = 'pgsql'
Datenbank-TypKonstante Postgres
tableArticles  = 'articles'
Article-Tabelle
tableAuthors  = 'authors'
Benutzer-Tabelle
tableCategories  = 'categories'
Kategorie-Tabelle
tableComments  = 'comments'
Kommentar-Tabelle
tableConfig  = 'config'
Config-Tabelle
tableCronjobs  = 'cronjobs'
Cronjob-Tabelle
tableFiles  = 'uploadfiles'
Dateiindex-Tabelle
tableIpAdresses  = 'blockedip'
Tabeller gesperrter IP-Adressen
tableModules  = 'modules'
Modul-Tabelle
tablePermissions  = 'permissions'
Tabelle für Berechtigungen
tableRevisions  = 'revisions'
Tabelle für revisionen
tableRoll  = 'userrolls'
Benutzerrollen-Tabelle
tableSessions  = 'sessions'
Sessions-Tabelle
tableShares  = 'shares'
Share-Count-Tabelle
tableSmileys  = 'smileys'
Smiley-Tabelle
tableTexts  = 'texts'
Wordsperre-Tabelle
viewArticleCounts  = 'articles_counts'
View for article counts
viewSessionUserdata  = 'session_userdata'
View for session and user data
$supportedDBMS  : mixed
Liste mit unterstützten Datenbanksystemen
$connection  : PDO
Datenbank-Verbindung
$dbname  : string
Database name
$dbprefix  : string
Tabellen-Prefix
$dbtype  : string
Datenbank-Typ
$driver  : sqlDriver
Datenbank-Treiber
$explain  : bool
SQL-Query via explain testen
$lastQueryErrorCode  : string
Common error code for last query
$lastQueryString  : string
letzter ausgeführter Datenbank-Querystring
$lastTable  : string
Tabelle, in welcher zuletzt eine Aktion durchgeführt wurde
$queryCount  : int
Anzahl an Datenbank abgesetzte Queries
$structCache  : array<string|int, mixed>
Table structure cache
__construct()  : void
Konstruktor
__destruct()  : mixed
Der Destruktor
addTableCols()  : bool
Add columns to database table by definition in object of type @see \fpcm\model\system\yatdl
addTableIndices()  : bool
Add columns to database table by definition in object of type @see \fpcm\model\system\yatdl
alter()  : bool
Ändert Tabellenstruktur via ALTER TABLE
checkDbVersion()  : string
Prüft, ob aktuelle Version des DBMS >= der empfohlenen Version ist
commit()  : bool
Starts transaction
concatString()  : string
Erzeugt CONCAT SQL-String
count()  : bool
Zählt nach den angebenen Einstellungen
createDbConfigFile()  : bool
Datei data/config/database.php erzeugen
createIndex()  : bool
Index auf eine Spalte in der übergebenen Tabelle erzeugen
createView()  : bool
Create view in database
dbLike()  : string
Erzeugt LIKE-SQL-String
delete()  : bool
Führt DELETE-Befehl auf DB aus
drop()  : bool
Tabelle via DROP TABLE löschen
exec()  : bool
Executes a sql query
execSqlFile()  : bool
Führt SQL-Datei aus
execYaTdl()  : bool
Parst YaTDL-Datei und führt SQL-Statement aus
fetch()  : mixed
Returns result set from database query
getDbprefix()  : string
Tabellen-Prefix zurückgeben
getDbtype()  : string
Datenbank-Typ zurückgeben
getDbVersion()  : string
Gibt Version des verbundenen Datenbank-Systems zurück
getLastInsertId()  : string
Liefert ID des letzten Insert-Eintrags
getLastQueryErrorCode()  : string
Returns common sql error code
getLastQueryString()  : string
Liefert zuletzt ausgeführten Query-String zurück
getMaxTableId()  : int
Liefert höchten Wert einer Tabellen-ID
getPdoDns()  : string
Returns PDO DNS string
getPdoOptions()  : string
Returns PDO options array
getQueryCount()  : int
Gibt Anzahl an ausgeführt Datenbank-Queries zurück
getRecommendVersion()  : string
Gibt Version des verbundenen Datenbank-Systems zurück
getStatementError()  : bool
Schreibt letzte Fehlermeldung des ausgefühtren Statements in DB-Log
getTableFiles()  : array<string|int, mixed>
Liefert YMl-Dateien aus Pfad zurück
getTableIndices()  : array<string|int, mixed>
Returns indices defined for the certain table and or column
getTablePrefixed()  : string
Kompletten Tabellen-Name mit Prefix zurückgeben
getTableStructure()  : array<string|int, mixed>
Returns database structure for certain table and/or column
getYaTDLDataTypes()  : array<string|int, mixed>
Gibt Datentypen-Map zurück für YATDL
implodeCols()  : string
Erzeugt CONCAT_WS SQL-String
inQuery()  : string
Creates IN-Query for prepared statement
insert()  : int
Execute insert query
limitQuery()  : string
Erzeugt LIMIT-SQL-String
optimize()  : bool
Erzeugt Query für Optimierungsvorgang auf Datenbank-Tabellen
orderBy()  : string
Erzeugt ORDER BY-SQL-String
query()  : PDOStatement
Führt ein SQL Kommando aus und gibt Result-Set zurück
removeTableCols()  : bool
Removes columns to database table by definition in object of type @see \fpcm\model\system\yatdl
reverseBool()  : bool
Negiert den Wert des übergebenen Feldes
select()  : mixed
Führt SELECT-Befehl auf DB aus
selectFetch()  : PDOStatement|array<string|int, mixed>
Executes select and fetch in one function
setExplain()  : mixed
SQL-EXPLAIN de/aktivieren
transaction()  : bool
Starts transaction
unionSelectFetch()  : array<string|int, mixed>
Executes UNION combined select and fetch
update()  : bool
Führt UPDATE-Befehl auf DB aus
updateMultiple()  : bool
Führt mehrere UPDATE-Befehl auf DB mit einmal aus
dieError()  : mixed
Error die
getLenghtTypes()  : array<string|int, mixed>
Return data types with length params
replacePrefixVar()  : bool
Replaces {{dbpref}} variable in SQL query

Constants

DBTYPE_MYSQLMARIADB

Datenbank-TypKonstante MySQL

public mixed DBTYPE_MYSQLMARIADB = 'mysql'
Tags
since
3.5

DBTYPE_POSTGRES

Datenbank-TypKonstante Postgres

public mixed DBTYPE_POSTGRES = 'pgsql'
Tags
since
3.5

tableArticles

Article-Tabelle

public mixed tableArticles = 'articles'

tableAuthors

Benutzer-Tabelle

public mixed tableAuthors = 'authors'

tableCategories

Kategorie-Tabelle

public mixed tableCategories = 'categories'

tableComments

Kommentar-Tabelle

public mixed tableComments = 'comments'

tableConfig

Config-Tabelle

public mixed tableConfig = 'config'

tableCronjobs

Cronjob-Tabelle

public mixed tableCronjobs = 'cronjobs'

tableFiles

Dateiindex-Tabelle

public mixed tableFiles = 'uploadfiles'

tableIpAdresses

Tabeller gesperrter IP-Adressen

public mixed tableIpAdresses = 'blockedip'

tableModules

Modul-Tabelle

public mixed tableModules = 'modules'

tablePermissions

Tabelle für Berechtigungen

public mixed tablePermissions = 'permissions'

tableRevisions

Tabelle für revisionen

public mixed tableRevisions = 'revisions'
Tags
since
3.3

tableRoll

Benutzerrollen-Tabelle

public mixed tableRoll = 'userrolls'

tableSessions

Sessions-Tabelle

public mixed tableSessions = 'sessions'

tableShares

Share-Count-Tabelle

public mixed tableShares = 'shares'

tableSmileys

Smiley-Tabelle

public mixed tableSmileys = 'smileys'

tableTexts

Wordsperre-Tabelle

public mixed tableTexts = 'texts'
Tags
since
3.2

viewArticleCounts

View for article counts

public mixed viewArticleCounts = 'articles_counts'
Tags
since
4.5

viewSessionUserdata

View for session and user data

public mixed viewSessionUserdata = 'session_userdata'
Tags
since
4.4.3

Properties

$supportedDBMS

Liste mit unterstützten Datenbanksystemen

public static mixed $supportedDBMS = array('mysql' => 'MySQL/ MariaDB', 'pgsql' => 'Postgres')
Tags
since
3.3

mysql => MySQL 5.5 + oder MariaDB 10 + pgsql => Postgres 9 +

$connection

Datenbank-Verbindung

private PDO $connection

$dbname

Database name

private string $dbname
Tags
since
4.5

$dbprefix

Tabellen-Prefix

private string $dbprefix

$dbtype

Datenbank-Typ

private string $dbtype
Tags
since
3.2

$explain

SQL-Query via explain testen

private bool $explain = false
Tags
since
3.6

$lastQueryErrorCode

Common error code for last query

private string $lastQueryErrorCode = null
Tags
since
4.4

$lastQueryString

letzter ausgeführter Datenbank-Querystring

private string $lastQueryString = ''

$lastTable

Tabelle, in welcher zuletzt eine Aktion durchgeführt wurde

private string $lastTable = ''
Tags
since
3.2

$queryCount

Anzahl an Datenbank abgesetzte Queries

private int $queryCount = 0

$structCache

Table structure cache

private array<string|int, mixed> $structCache = []

Methods

__construct()

Konstruktor

public __construct([array<string|int, mixed> $dbconfig = false ][, bool $dieOnError = true ]) : void
Parameters
$dbconfig : array<string|int, mixed> = false

alternative Datenbank-Zugangsdaten, wenn false werden Daten aus FPCM-Config genutzt

$dieOnError : bool = true

wenn Verbindung fehlschlägt, soll Ausführung vollständig abgebrochen werden

Return values
void

__destruct()

Der Destruktor

public __destruct() : mixed
Return values
mixed

addTableCols()

Add columns to database table by definition in object of type @see \fpcm\model\system\yatdl

public addTableCols(yatdl $yatdl) : bool
Parameters
$yatdl : yatdl
Return values
bool

addTableIndices()

Add columns to database table by definition in object of type @see \fpcm\model\system\yatdl

public addTableIndices(yatdl $yatdl) : bool
Parameters
$yatdl : yatdl
Tags
since
4.1
Return values
bool

alter()

Ändert Tabellenstruktur via ALTER TABLE

public alter(string $table, string $methode, string $field[, string $where = "" ][, bool $checkExists = true ]) : bool
Parameters
$table : string
$methode : string
$field : string
$where : string = ""
$checkExists : bool = true

Prüfung durchführen, ob Feld existiert

Return values
bool

checkDbVersion()

Prüft, ob aktuelle Version des DBMS >= der empfohlenen Version ist

public checkDbVersion() : string
Tags
since
3.4
Return values
string

commit()

Starts transaction

public commit() : bool
Tags
since
4.5.0-b3
Return values
bool

concatString()

Erzeugt CONCAT SQL-String

public concatString(array<string|int, mixed> $fields) : string
Parameters
$fields : array<string|int, mixed>
Tags
since
3.1.0
Return values
string

count()

Zählt nach den angebenen Einstellungen

public count(string $table[, string $countitem = '*' ][, string $where = null ][, array<string|int, mixed> $params = [] ]) : bool
Parameters
$table : string

In welcher Tabelle soll gezählt werden

$countitem : string = '*'

Welche Spalte soll gezählt werden

$where : string = null

Nach welchen Filterkriterien soll gezählt werden

$params : array<string|int, mixed> = []
Return values
bool

createDbConfigFile()

Datei data/config/database.php erzeugen

public createDbConfigFile(array<string|int, mixed> $data) : bool
Parameters
$data : array<string|int, mixed>
Tags
since
3.5.1
Return values
bool

createIndex()

Index auf eine Spalte in der übergebenen Tabelle erzeugen

public createIndex(string $table, string $indexName, string $field[, bool $isUnique = false ]) : bool
Parameters
$table : string
$indexName : string
$field : string
$isUnique : bool = false
Tags
since
3.3.1
Return values
bool

createView()

Create view in database

public createView(string $viewName, string $queryString) : bool
Parameters
$viewName : string
$queryString : string
Tags
since
4.4.3-rc1
Return values
bool

dbLike()

Erzeugt LIKE-SQL-String

public dbLike() : string
Tags
since
3.2.0
Return values
string

delete()

Führt DELETE-Befehl auf DB aus

public delete(string $table[, string $where = null ][, array<string|int, mixed> $params = [] ]) : bool
Parameters
$table : string
$where : string = null
$params : array<string|int, mixed> = []
Return values
bool

drop()

Tabelle via DROP TABLE löschen

public drop(string $table) : bool
Parameters
$table : string
Return values
bool

exec()

Executes a sql query

public exec(string $command[, array<string|int, mixed> $bindParams = [] ]) : bool
Parameters
$command : string
$bindParams : array<string|int, mixed> = []
Return values
bool

execSqlFile()

Führt SQL-Datei aus

public execSqlFile(string $path) : bool
Parameters
$path : string
Tags
since
3.2.0
Return values
bool

execYaTdl()

Parst YaTDL-Datei und führt SQL-Statement aus

public execYaTdl(string $path) : bool
Parameters
$path : string
Tags
since
3.2.0
Return values
bool

fetch()

Returns result set from database query

public fetch(PDOStatement $result[, bool $getAll = false ][, int $style = PDO::FETCH_OBJ ]) : mixed
Parameters
$result : PDOStatement
$getAll : bool = false
$style : int = PDO::FETCH_OBJ
Return values
mixed

getDbprefix()

Tabellen-Prefix zurückgeben

public getDbprefix() : string
Return values
string

getDbtype()

Datenbank-Typ zurückgeben

public getDbtype() : string
Tags
since
3.2
Return values
string

getDbVersion()

Gibt Version des verbundenen Datenbank-Systems zurück

public getDbVersion() : string
Tags
since
3.4
Return values
string

getLastInsertId()

Liefert ID des letzten Insert-Eintrags

public getLastInsertId() : string
Return values
string

getLastQueryErrorCode()

Returns common sql error code

public getLastQueryErrorCode() : string
Tags
since
4.4
Return values
string

getLastQueryString()

Liefert zuletzt ausgeführten Query-String zurück

public getLastQueryString() : string
Return values
string

getMaxTableId()

Liefert höchten Wert einer Tabellen-ID

public getMaxTableId(string $table) : int
Parameters
$table : string

Tabellen-Name

Return values
int

getPdoDns()

Returns PDO DNS string

public getPdoDns() : string
Return values
string

getPdoOptions()

Returns PDO options array

public getPdoOptions() : string
Return values
string

getQueryCount()

Gibt Anzahl an ausgeführt Datenbank-Queries zurück

public getQueryCount() : int
Tags
since
3.1.0
Return values
int

getRecommendVersion()

Gibt Version des verbundenen Datenbank-Systems zurück

public getRecommendVersion() : string
Tags
since
3.4
Return values
string

getStatementError()

Schreibt letzte Fehlermeldung des ausgefühtren Statements in DB-Log

public getStatementError(PDOStatement &$statement) : bool
Parameters
$statement : PDOStatement
Return values
bool

getTableFiles()

Liefert YMl-Dateien aus Pfad zurück

public static getTableFiles([string $path = false ]) : array<string|int, mixed>
Parameters
$path : string = false
Tags
since
3.3.2
Return values
array<string|int, mixed>

getTableIndices()

Returns indices defined for the certain table and or column

public getTableIndices(string $table[, string $field = false ][, bool $cache = true ]) : array<string|int, mixed>
Parameters
$table : string
$field : string = false
$cache : bool = true
Tags
since
4.1
Return values
array<string|int, mixed>

getTablePrefixed()

Kompletten Tabellen-Name mit Prefix zurückgeben

public getTablePrefixed(string $table) : string
Parameters
$table : string
Tags
since
3.4
Return values
string

getTableStructure()

Returns database structure for certain table and/or column

public getTableStructure(string $table[, string $field = false ][, string $cache = true ]) : array<string|int, mixed>
Parameters
$table : string
$field : string = false
$cache : string = true
Tags
since
3.3.2
Return values
array<string|int, mixed>

getYaTDLDataTypes()

Gibt Datentypen-Map zurück für YATDL

public getYaTDLDataTypes() : array<string|int, mixed>
Tags
since
3.2.0
Return values
array<string|int, mixed>

implodeCols()

Erzeugt CONCAT_WS SQL-String

public implodeCols(string $delim, array<string|int, mixed> $fields) : string
Parameters
$delim : string
$fields : array<string|int, mixed>
Tags
since
3.4
Return values
string

inQuery()

Creates IN-Query for prepared statement

public inQuery(string $field, array<string|int, mixed> $values[, bool $not = false ]) : string
Parameters
$field : string
$values : array<string|int, mixed>
$not : bool = false
Tags
since
4.2.1
Return values
string

insert()

Execute insert query

public insert(string $table, string $values) : int
Parameters
$table : string
$values : string
Return values
int

limitQuery()

Erzeugt LIMIT-SQL-String

public limitQuery(int $offset, int $limit) : string
Parameters
$offset : int
$limit : int
Return values
string

optimize()

Erzeugt Query für Optimierungsvorgang auf Datenbank-Tabellen

public optimize(string $table) : bool
Parameters
$table : string

Name der Tabelle

Tags
since
3.3.0
Return values
bool

orderBy()

Erzeugt ORDER BY-SQL-String

public orderBy(array<string|int, mixed> $conditions) : string
Parameters
$conditions : array<string|int, mixed>
Return values
string

query()

Führt ein SQL Kommando aus und gibt Result-Set zurück

public query(string $command[, array<string|int, mixed> $bindParams = [] ]) : PDOStatement
Parameters
$command : string

SQL String

$bindParams : array<string|int, mixed> = []

Paramater, welche gebunden werden sollen

Return values
PDOStatement

removeTableCols()

Removes columns to database table by definition in object of type @see \fpcm\model\system\yatdl

public removeTableCols(yatdl $yatdl) : bool
Parameters
$yatdl : yatdl
Return values
bool

reverseBool()

Negiert den Wert des übergebenen Feldes

public reverseBool(string|array<string|int, mixed> $table, string $field, string $where) : bool
Parameters
$table : string|array<string|int, mixed>
$field : string
$where : string
Return values
bool

select()

Führt SELECT-Befehl auf DB aus

public select(string $table[, string $item = '*' ][, string|null $where = null ][, array<string|int, mixed> $params = [] ][, bool $distinct = false ]) : mixed
Parameters
$table : string

select table

$item : string = '*'

select items

$where : string|null = null

select condition

$params : array<string|int, mixed> = []

select condition params

$distinct : bool = false

Distinct select

Return values
mixed

selectFetch()

Executes select and fetch in one function

public selectFetch(selectParams $obj) : PDOStatement|array<string|int, mixed>
Parameters
$obj : selectParams
Return values
PDOStatement|array<string|int, mixed>

setExplain()

SQL-EXPLAIN de/aktivieren

public setExplain(bool $explain) : mixed
Parameters
$explain : bool
Tags
since
3.6
Return values
mixed

transaction()

Starts transaction

public transaction() : bool
Tags
since
4.5.0-b3
Return values
bool

unionSelectFetch()

Executes UNION combined select and fetch

public unionSelectFetch(array<string|int, mixed> $selects[, int $fetchStyle = PDO::FETCH_OBJ ][, bool $returnResult = false ]) : array<string|int, mixed>
Parameters
$selects : array<string|int, mixed>
$fetchStyle : int = PDO::FETCH_OBJ
$returnResult : bool = false
Tags
since
4.5
Return values
array<string|int, mixed>

update()

Führt UPDATE-Befehl auf DB aus

public update(string $table, array<string|int, mixed> $fields[, array<string|int, mixed> $params = [] ][, string $where = null ]) : bool
Parameters
$table : string
$fields : array<string|int, mixed>
$params : array<string|int, mixed> = []
$where : string = null
Return values
bool

updateMultiple()

Führt mehrere UPDATE-Befehl auf DB mit einmal aus

public updateMultiple(string $table, array<string|int, mixed> $fields[, array<string|int, mixed> $params = [] ][, array<string|int, mixed> $where = [] ]) : bool
Parameters
$table : string
$fields : array<string|int, mixed>
$params : array<string|int, mixed> = []
$where : array<string|int, mixed> = []
Tags
since
3.5
Return values
bool

dieError()

Error die

private dieError() : mixed
Return values
mixed

getLenghtTypes()

Return data types with length params

private getLenghtTypes() : array<string|int, mixed>
Return values
array<string|int, mixed>

replacePrefixVar()

Replaces {{dbpref}} variable in SQL query

private replacePrefixVar(string &$sql) : bool
Parameters
$sql : string
Tags
since
4.5
Return values
bool

Search results