Kajona\System\System\Database

This class handles all traffic from and to the database and takes care of a correct tx-handling CHANGE WITH CARE! Since version 3.4, prepared statments are supported. As a parameter-escaping, only the ? char is allowed, named params are not supported at the moment.

Old plain queries are still allows, but will be discontinued around kajona 3.5 / 4.0. Up from kajona > 3.4.0
a warning will be generated when using the old apis.
When using prepared statements, all escaping is done by the database layer.
When using the old, plain queries, you have to escape all embedded arguments yourself by using dbsafeString()

Synopsis

class Database {
}

Members

private

  • $arrQueryCache
  • $arrTablesCache
  • $bitConnectedKajona\System\System\bool
    Flag indicating if the internal connection was setup.
  • $bitCurrentTxIsDirtyKajona\System\System\bool
    Set to true, if a rollback is requested, but there are still open tx.
  • $intNumber
  • $intNumberCache
  • $intNumberOfOpenTransactions — int
    The number of transactions currently opened
  • $objConfig
  • $objDB
  • $objDbDriverKajona\System\System\Db\DbDriverInterface
    Instance of the db-driver defined in the configs

Methods

private

  • __construct() — Constructor
  • dbconnect() — This method connects with the database
  • dbsafeParams() — Internal wrapper to dbsafeString, used to process a complete array of parameters as used by prepared statements.
  • getError() — Writes the last DB-Error to the screen
  • processQuery() — Parses a query to eliminate unnecessary characters such as whitespaces

public

  • __destruct() — Destructor.
  • _pQuery() — Sending a prepared statement to the database
  • _query() — Sending a query to the database
  • addColumn() — Adds a column to a table
  • changeColumn() — Changes a single column, e.g. the datatype
  • createTable() — Used to send a create table statement to the database By passing the query through this method, the driver can add db-specific commands.
  • dbsafeString() — Makes a string db-safe
  • dumpDb() — Dumps the current db Takes care of holding just the defined number of dumps in the filesystem, defined by _system_dbdump_amount_
  • encloseColumnName() — Allows the db-driver to add database-specific surroundings to column-names.
  • encloseTableName() — Allows the db-driver to add database-specific surroundings to table-names.
  • escape() — For some database vendors we need to escape the backslash character even if we are using prepared statements. This method unifies the behaviour. In order to select a column which contains a backslash you need to escape the value with this method
  • flushPreparedStatementsCache() — Helper to flush the precompiled queries stored at the db-driver.
  • flushQueryCache() — Method to flush the query-cache
  • flushTablesCache() — Method to flush the table-cache.
  • getArray() — Method to get an array of rows for a given query from the database
  • getArraySection() — Returns just a part of a recordset, defined by the start- and the end-rows, defined by the params.
  • getBitConnected()
  • getCacheSize() — Returns the number of items currently in the query-cache
  • getColumnsOfTable() — Looks up the columns of the given table.
  • getDatatype() — Returns the db-specific datatype for the kajona internal datatype.
  • getDbInfo() — Queries the current db-driver about common information
  • getInstance() — Method to get an instance of the db-class
  • getNumber() — Returns the number of queries sent to the database including those solved by the cache
  • getNumberCache() — Returns the number of queries solved by the cache
  • getPArray() — Method to get an array of rows for a given query from the database.
  • getPArraySection() — Returns just a part of a recordset, defined by the start- and the end-rows, defined by the params. Makes use of prepared statements <b>Note:</b> Use array-like counters, so the first row is startRow 0 whereas the n-th row is the (n-1)th key!!!
  • getPRow() — Returns one row from a result-set.
  • getRow() — Returns one row from a result-set
  • getTables() — Returns all tables used by the project
  • importDb() — Imports the given dump
  • multiInsert() — Creates a single query in order to insert multiple rows at one time.
  • prettifyQuery() — Helper to replace all param-placeholder with the matching value, only to be used to render a debuggable-statement.
  • removeColumn() — Removes a column from a table
  • renameTable() — Renames a table
  • transactionBegin() — Starts a transaction
  • transactionCommit() — Ends a tx successfully
  • transactionRollback() — Rollback of the current tx
  • validateDbCxData() — Tries to validate the passed connection data.