Class rex_sql

Klasse zur Verbindung und Interatkion mit der Datenbank.

see http://net.tutsplus.com/tutorials/php/why-you-should-be-using-phps-pdo-for-database-access/

rex_sql implements Iterator uses rex_factory_trait
Package: redaxo\core\sql
Located at redaxo/src/core/lib/sql/sql.php

Methods summary

protected
# __construct( integer $DBID = 1 )
protected
# selectDB( integer $DBID )

Stellt die Verbindung zur Datenbank her.

protected static PDO
# createConnection( string $host, string $database, string $login, string $password, boolean $persistent = false )
protected static boolean
# getQueryDBID( string $qry )

Gibt die DatenbankId der Abfrage (SQL) zurueck, oder false wenn die Abfrage keine DBID enthaelt.

protected static string
# stripQueryDBID( string & $qry )

Entfernt die DBID aus einer Abfrage (SQL) und gibt die DBID zurueck falls vorhanden, sonst false.

public static boolean|string
# getQueryType( string $qry )

Gibt den Typ der Abfrage (SQL) zurueck, oder false wenn die Abfrage keinen Typ enthaelt.

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.

public mixed
# setDBQuery( string $query, array $params = [], array $options = [] )

Setzt eine Abfrage (SQL) ab, wechselt die DBID falls vorhanden.

public mixed
# setDebug( boolean $debug = true )

Setzt Debugmodus an/aus.

public PDOStatement
# prepareQuery( string $qry )

Prepares a PDOStatement.

public mixed
# execute( array $params = [], array $options = [] )

Executes the prepared statement with the given input parameters.

public mixed
# setQuery( string $query, array $params = [], array $options = [] )

Executes the given sql-query.

public mixed
# setTable( string $table )

Setzt den Tabellennamen.

public mixed
# setRawValue( string $colName, string $value )

Sets the raw value of a column.

public mixed
# setValue( string $colName, mixed $value )

Set the value of a column.

public mixed
# setArrayValue( string $colName, array $value )

Set the array value of a column (json encoded).

public mixed
# setDateTimeValue( string $colName, integer|null $timestamp )

Sets the datetime value of a column.

public mixed
# setValues( array $valueArray )

Setzt ein Array von Werten zugleich.

public boolean
# hasValues( )

Returns whether values are set inside this rex_sql object.

protected boolean
# isValueOf( string $feld, string $prop )

Prueft den Wert einer Spalte der aktuellen Zeile ob ein Wert enthalten ist.

public mixed
# addRecord( callable $callback )

Adds a record for multi row/batch operations.

public mixed
# setWhere( string|array $where, array $whereParams = null )

Setzt die WHERE Bedienung der Abfrage.

public mixed
# getValue( string $colName )

Returns the value of a column.

public array
# getArrayValue( string $colName )

Returns the array value of a (json encoded) column.

public integer|null
# getDateTimeValue( string $colName )

Returns the unix timestamp of a datetime column.

protected mixed
# fetchValue( string $feldname )
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().

public boolean
# hasValue( string $feldname )

Prueft, ob eine Spalte im Resultset vorhanden ist.

public boolean|null
# isNull( string $feldname )

Prueft, ob das Feld mit dem Namen $feldname Null ist.

public null|integer
# getRows( )

Gibt die Anzahl der Zeilen zurueck.

public integer
# getFields( )

Gibt die Anzahl der Felder/Spalten zurueck.

protected string
# buildPreparedValues( )

Baut den SET bestandteil mit der verfuegbaren values zusammen und gibt diesen zurueck.

public string
# getWhere( )
public mixed
# select( string $fields = '*' )

Setzt eine Select-Anweisung auf die angegebene Tabelle mit den WHERE Parametern ab.

public mixed
# update( )

Setzt eine Update-Anweisung auf die angegebene Tabelle mit den angegebenen Werten und WHERE Parametern ab.

public mixed
# insert( )

Setzt eine Insert-Anweisung auf die angegebene Tabelle mit den angegebenen Werten ab.

public mixed
# insertOrUpdate( )
public mixed
# replace( )

Setzt eine Replace-Anweisung auf die angegebene Tabelle mit den angegebenen Werten ab.

public mixed
# delete( )

Setzt eine Delete-Anweisung auf die angegebene Tabelle mit den angegebenen WHERE Parametern ab.

public mixed
# flushValues( )

Stellt alle Values, die mit setValue() gesetzt wurden, zurueck.

public
# hasNext( )

Prueft ob das Resultset weitere Datensaetze enthaelt.

public mixed
# reset( )

Setzt den Cursor des Resultsets zurueck zum Anfang.

public
# getLastId( )

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.

public array
# getArray( string $query = null, array $params = [], integer $fetchType = PDO::FETCH_ASSOC )

Laedt das komplette Resultset in ein Array und gibt dieses zurueck.

public string
# getErrno( )

Gibt die zuletzt aufgetretene Fehlernummer zurueck.

public integer
# getMysqlErrno( )
public
# getError( )

Gibt den zuletzt aufgetretene Fehler zurueck.

public boolean
# hasError( )

Prueft, ob ein Fehler aufgetreten ist.

protected
# printError( string $qry, array $params )

Gibt die letzte Fehlermeldung aus.

public integer
# setNewId( string $field, integer $start_id = 0 )

Setzt eine Spalte auf den naechst moeglich auto_increment Wert.

public null|array
# getFieldnames( )

Gibt die Spaltennamen des ResultSets zurueck.

public null|array
# getTablenames( )
public string
# escape( string $value )

Escaped den uebergeben Wert fuer den DB Query.

public string
# escapeIdentifier( string $name )

Escapes and adds backsticks around.

public mixed
# addGlobalUpdateFields( string $user = null )
public mixed
# addGlobalCreateFields( string $user = null )
public boolean
# beginTransaction( )

Starts a database transaction.

public boolean
# rollBack( )

Rollback a already started database transaction.

public boolean
# commit( )

Commit a already started database transaction.

public boolean
# inTransaction( )
public mixed
# transactional( callable $callable )

Convenience method which executes the given callable within a transaction.

public
# rewind( )
public mixed
# current( )
public
# key( )
public
# next( )
public
# valid( )
public static string
# showCreateTable( string $table, integer $DBID = 1 )

Erstellt das CREATE TABLE Statement um die Tabelle $table der Datenbankverbindung $DBID zu erstellen.

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.

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.

public array
# getTables( null|string $tablePrefix = null )

Sucht alle Tabellen der Datenbankverbindung $DBID. Falls $tablePrefix gesetzt ist, werden nur dem Prefix entsprechende Tabellen gesucht.

public array
# getViews( null|string $tablePrefix = null )

Sucht alle Views der Datenbankverbindung $DBID. Falls $tablePrefix gesetzt ist, werden nur dem Prefix entsprechende Views gesucht.

public static array
# showColumns( string $table, integer $DBID = 1 )

Sucht Spalteninformationen der Tabelle $table der Datenbankverbindung $DBID.

public static mixed
# getServerVersion( integer $DBID = 1 )

Gibt die Serverversion zurueck.

public static static
# factory( integer $DBID = 1 )

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

Methods used from rex_factory_trait

callFactoryClass(), getFactoryClass(), hasFactoryClass(), setFactoryClass()

Constants summary

string FORMAT_DATETIME

Default SQL datetime format.

#'Y-m-d H:i:s'
string OPT_BUFFERED

Controls query buffering.

#'buffered'

Properties summary

protected mixed $debug
protected mixed $values
protected mixed $rawValues
protected mixed $fieldnames
protected mixed $rawFieldnames
protected mixed $tablenames
protected mixed $lastRow
protected mixed $table
protected mixed $wherevar
protected mixed $whereParams
protected mixed $rows
protected mixed $counter
protected mixed $query
protected mixed $params
protected mixed $DBID
protected self[] $records
protected PDOStatement $stmt
protected static PDO[] $pdo
#[]