protected
|
|
|
protected
|
#
selectDB( integer $DBID )
Stellt die Verbindung zur Datenbank her.
Stellt die Verbindung zur Datenbank her.
Parameters
Throws
|
|
protected static
PDO
|
#
createConnection( string $host, string $database, string $login, string $password, boolean $persistent = false )
Parameters
- $host
- $database
- $login
- $password
- $persistent
Returns
PDO PDO
|
|
protected static
boolean
|
#
getQueryDBID( string $qry )
Gibt die DatenbankId der Abfrage (SQL) zurueck, oder false wenn die Abfrage
keine DBID enthaelt.
Gibt die DatenbankId der Abfrage (SQL) zurueck, oder false wenn die Abfrage
keine DBID enthaelt.
Parameters
Returns
boolean bool
|
|
protected static
string
|
#
stripQueryDBID( string & $qry )
Entfernt die DBID aus einer Abfrage (SQL) und gibt die DBID zurueck falls
vorhanden, sonst false.
Entfernt die DBID aus einer Abfrage (SQL) und gibt die DBID zurueck falls
vorhanden, sonst false.
Parameters
Returns
string string
|
|
public static
boolean|string
|
#
getQueryType( string $qry )
Gibt den Typ der Abfrage (SQL) zurueck, oder false wenn die Abfrage keinen
Typ enthaelt.
Gibt den Typ der Abfrage (SQL) zurueck, oder false wenn die Abfrage keinen
Typ enthaelt.
Moegliche Typen:
- SELECT
- SHOW
- UPDATE
- INSERT
- DELETE
- REPLACE
- CREATE
- CALL
- OPTIMIZE
Parameters
Returns
boolean|string bool|string
|
|
public static
string
|
#
datetime( integer|null $timestamp = null )
Returns a datetime string in sql datetime format (Y-m-d H:i:s) using the
given timestamp or the current time if no timestamp (or null ) is
given.
Returns a datetime string in sql datetime format (Y-m-d H:i:s) using the
given timestamp or the current time if no timestamp (or null ) is
given.
Parameters
Returns
string string
|
|
public
mixed
|
#
setDBQuery( string $query, array $params = [], array $options = [] )
Setzt eine Abfrage (SQL) ab, wechselt die DBID falls vorhanden.
Setzt eine Abfrage (SQL) ab, wechselt die DBID falls vorhanden.
Parameters
- $query
- The sql-query
- $params
- An optional array of statement parameter
- $options
- For possible option keys view <code>rex_sql::OPT_*</code> constants
Returns
mixed $this
Throws
|
|
public
mixed
|
#
setDebug( boolean $debug = true )
Setzt Debugmodus an/aus.
Parameters
Returns
mixed $this the current rex_sql object
|
|
public
PDOStatement
|
#
prepareQuery( string $qry )
Prepares a PDOStatement.
Parameters
- $qry
- A query string with placeholders
Returns
PDOStatement The prepared statement
Throws
|
|
public
mixed
|
#
execute( array $params = [], array $options = [] )
Executes the prepared statement with the given input parameters.
Executes the prepared statement with the given input parameters.
Parameters
- $params
- Array of input parameters
- $options
- For possible option keys view <code>rex_sql::OPT_*</code> constants
Returns
mixed $this
Throws
|
|
public
mixed
|
#
setQuery( string $query, array $params = [], array $options = [] )
Executes the given sql-query.
Executes the given sql-query.
If parameters will be provided, a prepared statement will be executed.
example 1: $sql->setQuery('SELECT * FROM mytable where id=:id', ['id'
=> 3]);
NOTE: named-parameters/?-placeholders are not supported in LIMIT clause!
Parameters
- $query
- The sql-query
- $params
- An optional array of statement parameter
- $options
- For possible option keys view <code>rex_sql::OPT_*</code> constants
Returns
mixed $this
Throws
|
|
public
mixed
|
#
setTable( string $table )
Setzt den Tabellennamen.
Parameters
Returns
mixed $this the current rex_sql object
|
|
public
mixed
|
#
setRawValue( string $colName, string $value )
Sets the raw value of a column.
Sets the raw value of a column.
Parameters
- $colName
- Name of the column
- $value
- The raw value
Returns
mixed $this the current rex_sql object
|
|
public
mixed
|
#
setValue( string $colName, mixed $value )
Set the value of a column.
Set the value of a column.
Parameters
- $colName
- Name of the column
- $value
- The value
Returns
mixed $this the current rex_sql object
|
|
public
mixed
|
#
setArrayValue( string $colName, array $value )
Set the array value of a column (json encoded).
Set the array value of a column (json encoded).
Parameters
- $colName
- Name of the column
- $value
- The value
Returns
mixed $this the current rex_sql object
|
|
public
mixed
|
#
setDateTimeValue( string $colName, integer|null $timestamp )
Sets the datetime value of a column.
Sets the datetime value of a column.
Parameters
- $colName
- Name of the column
- $timestamp
- Unix timestamp (if <code>null</code> is given, the current time is used)
Returns
mixed $this the current rex_sql object
|
|
public
mixed
|
#
setValues( array $valueArray )
Setzt ein Array von Werten zugleich.
Setzt ein Array von Werten zugleich.
Parameters
- $valueArray
- Ein Array von Werten
Returns
mixed $this the current rex_sql object
|
|
public
boolean
|
#
hasValues( )
Returns whether values are set inside this rex_sql object.
Returns whether values are set inside this rex_sql object.
Returns
boolean True if value isset and not null, otherwise False
|
|
protected
boolean
|
#
isValueOf( string $feld, string $prop )
Prueft den Wert einer Spalte der aktuellen Zeile ob ein Wert enthalten
ist.
Prueft den Wert einer Spalte der aktuellen Zeile ob ein Wert enthalten
ist.
Parameters
- $feld
- Spaltenname des zu pruefenden Feldes
- $prop
- Wert, der enthalten sein soll
Returns
boolean bool
Throws
|
|
public
mixed
|
#
addRecord( callable $callback )
Adds a record for multi row/batch operations.
Adds a record for multi row/batch operations.
This method can only be used in combination with insert() and
replace() .
Example: $sql->addRecord(function (rex_sql $record) {
$record->setValue('title', 'Foo'); $record->setRawValue('created',
'NOW()'); });
Parameters
- $callback
- The callback receives a new <code>rex_sql</code> instance for the new record and
must set the values of the new record on that instance (see example above)
Returns
mixed $this
|
|
public
mixed
|
#
setWhere( string|array $where, array $whereParams = null )
Setzt die WHERE Bedienung der Abfrage.
Setzt die WHERE Bedienung der Abfrage.
example 1: $sql->setWhere(['id' => 3, 'field' => '']); // results in
id = 3 AND field = '' $sql->setWhere([['id' => 3, 'field' => '']]); //
results in id = 3 OR field = ''
example 2: $sql->setWhere('myid = :id OR anotherfield = :field', ['id'
=> 3, 'field' => '']);
example 3 (deprecated): $sql->setWhere('myid="35" OR abc="zdf"');
Parameters
Returns
mixed $this the current rex_sql object
Throws
|
|
public
mixed
|
#
getValue( string $colName )
Returns the value of a column.
Returns the value of a column.
Parameters
- $colName
- Name of the column
Returns
mixed mixed
Throws
|
|
public
array
|
#
getArrayValue( string $colName )
Returns the array value of a (json encoded) column.
Returns the array value of a (json encoded) column.
Parameters
- $colName
- Name of the column
Returns
array array
Throws
|
|
public
integer|null
|
#
getDateTimeValue( string $colName )
Returns the unix timestamp of a datetime column.
Returns the unix timestamp of a datetime column.
Parameters
- $colName
- Name of the column
Returns
integer|null Unix timestamp or null if the column is null or not in
sql datetime format
Throws
|
|
protected
mixed
|
#
fetchValue( string $feldname )
Parameters
Returns
mixed mixed
|
|
public
mixed
|
#
getRow( integer $fetch_type = PDO::FETCH_ASSOC )
Gibt den Wert der aktuellen Zeile im ResultSet zurueck Falls es noch keine
erste Zeile (lastRow) gibt, wird der Satzzeiger initialisiert. Weitere
Satzwechsel mittels next().
Gibt den Wert der aktuellen Zeile im ResultSet zurueck Falls es noch keine
erste Zeile (lastRow) gibt, wird der Satzzeiger initialisiert. Weitere
Satzwechsel mittels next().
Parameters
Returns
mixed mixed
|
|
public
boolean
|
#
hasValue( string $feldname )
Prueft, ob eine Spalte im Resultset vorhanden ist.
Prueft, ob eine Spalte im Resultset vorhanden ist.
Parameters
- $feldname
- Name der Spalte
Returns
boolean bool
|
|
public
boolean|null
|
#
isNull( string $feldname )
Prueft, ob das Feld mit dem Namen $feldname Null ist.
Prueft, ob das Feld mit dem Namen $feldname Null ist.
Falls das Feld nicht vorhanden ist, wird Null zurueckgegeben, sonst
True/False
Parameters
Returns
boolean|null bool|null
Throws
|
|
public
null|integer
|
#
getRows( )
Gibt die Anzahl der Zeilen zurueck.
Gibt die Anzahl der Zeilen zurueck.
Returns
null|integer null|int
|
|
public
integer
|
#
getFields( )
Gibt die Anzahl der Felder/Spalten zurueck.
Gibt die Anzahl der Felder/Spalten zurueck.
Returns
integer int
|
|
protected
string
|
#
buildPreparedValues( )
Baut den SET bestandteil mit der verfuegbaren values zusammen und gibt diesen
zurueck.
Baut den SET bestandteil mit der verfuegbaren values zusammen und gibt diesen
zurueck.
Returns
string string
See
|
|
public
string
|
|
|
public
mixed
|
#
select( string $fields = '*' )
Setzt eine Select-Anweisung auf die angegebene Tabelle mit den WHERE
Parametern ab.
Setzt eine Select-Anweisung auf die angegebene Tabelle mit den WHERE
Parametern ab.
Parameters
Returns
mixed $this
Throws
|
|
public
mixed
|
#
update( )
Setzt eine Update-Anweisung auf die angegebene Tabelle mit den angegebenen
Werten und WHERE Parametern ab.
Setzt eine Update-Anweisung auf die angegebene Tabelle mit den angegebenen
Werten und WHERE Parametern ab.
Returns
mixed $this
Throws
|
|
public
mixed
|
#
insert( )
Setzt eine Insert-Anweisung auf die angegebene Tabelle mit den angegebenen
Werten ab.
Setzt eine Insert-Anweisung auf die angegebene Tabelle mit den angegebenen
Werten ab.
Returns
mixed $this
Throws
|
|
public
mixed
|
|
|
public
mixed
|
#
replace( )
Setzt eine Replace-Anweisung auf die angegebene Tabelle mit den angegebenen
Werten ab.
Setzt eine Replace-Anweisung auf die angegebene Tabelle mit den angegebenen
Werten ab.
Returns
mixed $this
Throws
|
|
public
mixed
|
#
delete( )
Setzt eine Delete-Anweisung auf die angegebene Tabelle mit den angegebenen
WHERE Parametern ab.
Setzt eine Delete-Anweisung auf die angegebene Tabelle mit den angegebenen
WHERE Parametern ab.
Returns
mixed $this
Throws
|
|
public
mixed
|
#
flushValues( )
Stellt alle Values, die mit setValue() gesetzt wurden, zurueck.
Stellt alle Values, die mit setValue() gesetzt wurden, zurueck.
Returns
mixed $this the current rex_sql object
See
|
|
public
|
#
hasNext( )
Prueft ob das Resultset weitere Datensaetze enthaelt.
Prueft ob das Resultset weitere Datensaetze enthaelt.
|
|
public
mixed
|
#
reset( )
Setzt den Cursor des Resultsets zurueck zum Anfang.
Setzt den Cursor des Resultsets zurueck zum Anfang.
Returns
mixed $this the current rex_sql object
Throws
|
|
public
|
#
getLastId( )
Gibt die letzte InsertId zurueck.
Gibt die letzte InsertId zurueck.
|
|
public
array
|
#
getDBArray( string $query = null, array $params = [], integer $fetchType = PDO::FETCH_ASSOC )
Laedt das komplette Resultset in ein Array und gibt dieses zurueck und
wechselt die DBID falls vorhanden.
Laedt das komplette Resultset in ein Array und gibt dieses zurueck und
wechselt die DBID falls vorhanden.
Parameters
- $query
- The sql-query
- $params
- An optional array of statement parameter
- $fetchType
Returns
array array
Throws
|
|
public
array
|
#
getArray( string $query = null, array $params = [], integer $fetchType = PDO::FETCH_ASSOC )
Laedt das komplette Resultset in ein Array und gibt dieses zurueck.
Laedt das komplette Resultset in ein Array und gibt dieses zurueck.
Parameters
- $query
- The sql-query
- $params
- An optional array of statement parameter
- $fetchType
Returns
array array
Throws
|
|
public
string
|
#
getErrno( )
Gibt die zuletzt aufgetretene Fehlernummer zurueck.
Gibt die zuletzt aufgetretene Fehlernummer zurueck.
Returns
string string
|
|
public
integer
|
|
|
public
|
#
getError( )
Gibt den zuletzt aufgetretene Fehler zurueck.
Gibt den zuletzt aufgetretene Fehler zurueck.
|
|
public
boolean
|
#
hasError( )
Prueft, ob ein Fehler aufgetreten ist.
Prueft, ob ein Fehler aufgetreten ist.
Returns
boolean bool
|
|
protected
|
#
printError( string $qry, array $params )
Gibt die letzte Fehlermeldung aus.
Gibt die letzte Fehlermeldung aus.
Parameters
|
|
public
integer
|
#
setNewId( string $field, integer $start_id = 0 )
Setzt eine Spalte auf den naechst moeglich auto_increment Wert.
Setzt eine Spalte auf den naechst moeglich auto_increment Wert.
Parameters
- $field
- Name der Spalte
- $start_id
Returns
integer int
Throws
|
|
public
null|array
|
#
getFieldnames( )
Gibt die Spaltennamen des ResultSets zurueck.
Gibt die Spaltennamen des ResultSets zurueck.
Returns
null|array null|array
|
|
public
null|array
|
|
|
public
string
|
#
escape( string $value )
Escaped den uebergeben Wert fuer den DB Query.
Escaped den uebergeben Wert fuer den DB Query.
Parameters
- $value
- den zu escapenden Wert
Returns
string string
|
|
public
string
|
#
escapeIdentifier( string $name )
Escapes and adds backsticks around.
Escapes and adds backsticks around.
Parameters
Returns
string string
|
|
public
mixed
|
#
addGlobalUpdateFields( string $user = null )
Parameters
- $user
- the name of the user who created the dataset. Defaults to the current user
Returns
mixed $this the current rex_sql object
|
|
public
mixed
|
#
addGlobalCreateFields( string $user = null )
Parameters
- $user
- the name of the user who updated the dataset. Defaults to the current user
Returns
mixed $this the current rex_sql object
|
|
public
boolean
|
#
beginTransaction( )
Starts a database transaction.
Starts a database transaction.
Returns
boolean Indicating whether the transaction was successfully started
Throws
|
|
public
boolean
|
#
rollBack( )
Rollback a already started database transaction.
Rollback a already started database transaction.
Returns
boolean Indicating whether the transaction was successfully rollbacked
Throws
|
|
public
boolean
|
#
commit( )
Commit a already started database transaction.
Commit a already started database transaction.
Returns
boolean Indicating whether the transaction was successfully committed
Throws
|
|
public
boolean
|
#
inTransaction( )
Returns
boolean Whether a transaction was already started/is already running.
|
|
public
mixed
|
#
transactional( callable $callable )
Convenience method which executes the given callable within a
transaction.
Convenience method which executes the given callable within a
transaction.
In case the callable throws, the transaction will automatically rolled back.
In case no error happens, the transaction will be committed after the callable
was called.
Parameters
Returns
mixed mixed
Throws
Throwable Throwable
|
|
public
|
#
rewind( )
Throws
See
Implementation of
Iterator::rewind()
|
|
public
mixed
|
#
current( )
Returns
mixed $this
See
Implementation of
Iterator::current()
|
|
public
|
#
key( )
See
Implementation of
Iterator::key()
|
|
public
|
#
next( )
See
Implementation of
Iterator::next()
|
|
public
|
#
valid( )
See
Implementation of
Iterator::valid()
|
|
public static
string
|
#
showCreateTable( string $table, integer $DBID = 1 )
Erstellt das CREATE TABLE Statement um die Tabelle $table der
Datenbankverbindung $DBID zu erstellen.
Erstellt das CREATE TABLE Statement um die Tabelle $table der
Datenbankverbindung $DBID zu erstellen.
Parameters
- $table
- Name der Tabelle
- $DBID
- Id der Datenbankverbindung
Returns
string CREATE TABLE Sql-Statement zu erstsellung der Tabelle
Throws
|
|
public static
array
|
#
showTables( integer $DBID = 1, null|string $tablePrefix = null )
Sucht alle Tabellen/Views der Datenbankverbindung $DBID. Falls $tablePrefix
gesetzt ist, werden nur dem Prefix entsprechende Tabellen gesucht.
Sucht alle Tabellen/Views der Datenbankverbindung $DBID. Falls $tablePrefix
gesetzt ist, werden nur dem Prefix entsprechende Tabellen gesucht.
Deprecated
since 5.6.2, use non-static getTablesAndViews instead.
Parameters
- $DBID
- Id der Datenbankverbindung
- $tablePrefix
- Zu suchender Tabellennamen-Prefix
Returns
array Ein Array von Tabellennamen
Throws
|
|
public
array
|
#
getTablesAndViews( null|string $tablePrefix = null )
Sucht alle Tabellen/Views der Datenbankverbindung $DBID. Falls $tablePrefix
gesetzt ist, werden nur dem Prefix entsprechende Tabellen gesucht.
Sucht alle Tabellen/Views der Datenbankverbindung $DBID. Falls $tablePrefix
gesetzt ist, werden nur dem Prefix entsprechende Tabellen gesucht.
Parameters
- $tablePrefix
- Zu suchender Tabellennamen-Prefix
Returns
array Ein Array von Tabellennamen
Throws
|
|
public
array
|
#
getTables( null|string $tablePrefix = null )
Sucht alle Tabellen der Datenbankverbindung $DBID. Falls $tablePrefix gesetzt
ist, werden nur dem Prefix entsprechende Tabellen gesucht.
Sucht alle Tabellen der Datenbankverbindung $DBID. Falls $tablePrefix gesetzt
ist, werden nur dem Prefix entsprechende Tabellen gesucht.
Parameters
- $tablePrefix
- Zu suchender Tabellennamen-Prefix
Returns
array Ein Array von Tabellennamen
Throws
|
|
public
array
|
#
getViews( null|string $tablePrefix = null )
Sucht alle Views der Datenbankverbindung $DBID. Falls $tablePrefix gesetzt
ist, werden nur dem Prefix entsprechende Views gesucht.
Sucht alle Views der Datenbankverbindung $DBID. Falls $tablePrefix gesetzt
ist, werden nur dem Prefix entsprechende Views gesucht.
Parameters
- $tablePrefix
- Zu suchender Tabellennamen-Prefix
Returns
array Ein Array von Viewnamen
Throws
|
|
public static
array
|
#
showColumns( string $table, integer $DBID = 1 )
Sucht Spalteninformationen der Tabelle $table der Datenbankverbindung
$DBID.
Sucht Spalteninformationen der Tabelle $table der Datenbankverbindung
$DBID.
Beispiel fuer den Rueckgabewert:
Array ( [0] => Array ( [name] => pid [type] => int(11) [null] =>
NO [key] => PRI [default] => [extra] => auto_increment ) [1] =>
Array ( [name] => id [type] => int(11) [null] => NO [key] => MUL
[default] => [extra] => ) )
Parameters
- $table
- Name der Tabelle
- $DBID
- Id der Datenbankverbindung
Returns
array Ein mehrdimensionales Array das die Metadaten enthaelt
Throws
|
|
public static
mixed
|
#
getServerVersion( integer $DBID = 1 )
Gibt die Serverversion zurueck.
Gibt die Serverversion zurueck.
Die Versionsinformation ist erst bekannt, nachdem der rex_sql Konstruktor
einmalig erfolgreich durchlaufen wurde.
Parameters
Returns
mixed mixed
|
|
public static
static
|
#
factory( integer $DBID = 1 )
Creates a rex_sql instance.
Creates a rex_sql instance.
Parameters
Returns
static Returns a rex_sql instance
|
|
public static
boolean|string
|
#
checkDbConnection( string $host, string $login, string $pw, string $dbname, boolean $createDb = false )
Prueft die uebergebenen Zugangsdaten auf gueltigkeit und legt ggf. die
Datenbank an.
Prueft die uebergebenen Zugangsdaten auf gueltigkeit und legt ggf. die
Datenbank an.
Parameters
- $host
- $login
- $pw
- $dbname
- $createDb
Returns
boolean|string bool|string
|
|