Class OCSP_DB_mySQL

Description

Implements interfaces:

handels mySQL database connections / operations

Located in /db/OCSP_DB_mySQL.phpclass (line 50)

OCSP_DB
   |
   --OCSP_DB_mySQL
Variable Summary
 static mixed $dbTableDefinitions
 resource $myConnId
Method Summary
 void addColumn (string $aTable, string $colName,  &$dbDesc, [boolean $debug = False], array $dbDesc)
 string checkQuery (string $aQuery, [int $type = PQT_SELECT], [boolean $debug = False])
 mixed checkValue (string $aType, mixed $aValue, [int $maxLen = 255], [boolean $debug = False])
 boolean connect ([string $conffile = ""], [boolean $asPublic = True], [boolean $asAdmin = False], [boolean $debug = False])
 void createTable ( $tblName,  $cols, [ $debug = False])
 bool deleteArray (string $table,  &$valueArr, [boolean $debug = False], array $valueArr)
 boolean deleteRows (string $table, array $delKeys, [ $backup = True], [boolean $debug = False])
 void disconnect ()
 void errorMsg ([string $msg = ""])
 void executeCmd (string $aCmd, [boolean $debug = False], [boolean $secMode = True])
 void fetchArray ( $aCursor, [ $useNames = True])
 void freeCursor ( $aCursor)
 array getArray (string $aTable, [array $conditions = NULL], [int $offset = 0], [int $limit = 0], [string $orderBy = ""], [boolean $debug = False])
 string getColumnDef (array $dbDesc, [boolean $debug = False])
 array getDBTblColNames (string $aTable, [boolean $debug = False])
 array getDBTblDesc (strint $table, [bool $debug = False])
 array getDBTblList ([bool $debug = False])
 string getDBType ()
 string getErrorMsg ()
 int getErrorNo ()
 array getPrimaryKeys (string $aTbl, [boolean $debug = False])
 array getQueryArray (string $query, [boolean $debug = False])
 double getTimeStamp (stirng $aDateVal, [boolean $debug = True])
 boolean initConn ()
 int insert (string $query, [string $aTable = ""], [string $keyfld = ""], [boolean $withLock = True], [boolean $debug = False])
 int insertArray (string $table, array $valueArr, [boolean $debug = False], [string $idFld = ""])
 void logCmd ([strint $aQuery = ""])
 void numOfRows ( $aCursor)
 void publicConnect ([ $conffile = ""], [ $keepConnection = True])
 string qs_getDateStmt (OCSP_DATE $aDateObj, [boolean $slashed = True])
 string qs_getLikeStmt (string $searchStr, [boolean $toUpper = False], [boolean $inline = True], [boolean $debug = False])
 string qs_getNowStmt ()
 string qs_getNullStmt ()
 string qs_getPassword (string $aValue)
 string qs_getSlashedValue (string $aValue)
 string qs_getWhereClause ([array $conditions = NULL], [boolean $debug = False])
 string qs_getWhereIn (string $col, array $valArr, [boolean $valuesAreString = True])
 string qs_ifNullStmt (string $column, [string $default = ""])
 OCSP_CURSOR_mySQL query ([string $aQuery = ""], [boolean $secMode = True], [boolean $withErrMsg = False], [boolean $autoFree = True], [boolean $useBuffer = True])
 array queryArray (string $aQuery, [int $keyFld = 0], [int $valueFld = 0], [boolean $secMode = True], [boolean $debug = False])
 mixed quickQuery (string $aQuery, [int $colNr = -1], [boolean $withErrMsg = False], [boolean $useNames = True], [boolean $secMode = True], [boolean $debug = False])
 void replace (string $table, array $valueArr, [boolean $debug = False])
 bool replaceArray (string $table,  &$valueArr, [boolean $debug = False], array $valueArr)
 boolean resortTable (string $table, string $orderFld, [string $where = ""], [string $debug = False], [string $orderby = ""], [string $groupbyCol = ""], [int $startIdx = 1])
 string server_info ()
 bool tblExists (string $aTable, [boolean $debug = False])
 boolean tblHasColumn (string $table, string $colName, [boolean $debug = False])
 void truncateTable (string $aTable, [boolean $backup = True], [ $debug = False])
 int updateArray (string $aTable, array $conditions, array $values, [int $limit = 0], [boolean $debug = False])
Variables
static mixed $dbTableDefinitions = array() (line 60)

array of already seen tables definitions

  • staticvar: array $dbTableDefinitions:
resource $myConnId = "" (line 69)
  • access: private

Inherited Variables

Inherited from OCSP_DB

OCSP_DB::$debugInsert
OCSP_DB::$iam_connected
OCSP_DB::$iam_initialized
OCSP_DB::$myConfFile
OCSP_DB::$myDB
OCSP_DB::$myServer
Methods
addColumn (line 1677)

adds a column to a table

  • since: pk-04-10-08
  • access: public
void addColumn (string $aTable, string $colName,  &$dbDesc, [boolean $debug = False], array $dbDesc)
  • string $aTable
  • string $colName
  • array $dbDesc
  • boolean $debug
  • &$dbDesc

Redefinition of:
OCSP_DB::addColumn()
adds a column to a table
checkQuery (line 333)

checks a query string if it's save to use

  • version: pk-04-11-12
  • todo: only PQT_SELECT and PQT_UNION are checked for the moment
string checkQuery (string $aQuery, [int $type = PQT_SELECT], [boolean $debug = False])
  • string $aQuery
  • int $type: PQT_[querytype]
  • boolean $debug
checkValue (line 645)

converts php variables to db save values adds slashes and " to enclose strings

special values:

  • datetime,date,time: #NOW #NOW_DATE #NOW_TIME
  • timestamp: NOW() CURRENT_TIMESTAMP

  • version: pk-05-01-13 tinyint added
  • version: pk-05-05-18 bugfix timestamp
  • version: pk-05-11-25 special value added
  • version: pk-06-11-28 double added changes in default
mixed checkValue (string $aType, mixed $aValue, [int $maxLen = 255], [boolean $debug = False])
  • string $aType: database type
  • mixed $aValue: column value
  • int $maxLen: max Field Len
  • boolean $debug: show debug info
connect (line 125)

connects to the database

  • global: $OCSP_CONF 0:
  • global: $OCSP_OBJ 1:
  • version: pk-07-06-01
  • version: pk-08-10-15
  • access: public
boolean connect ([string $conffile = ""], [boolean $asPublic = True], [boolean $asAdmin = False], [boolean $debug = False])
  • string $conffile: file containing the database configuration
  • boolean $asPublic: use public user from the conf
  • boolean $asAdmin: use the admin user from the conf
  • boolean $debug
createTable (line 1497)
  • access: public
void createTable ( $tblName,  $cols, [ $debug = False])
  • $tblName
  • $cols
  • $debug
deleteArray (line 1063)

deletes an existing row where the primary key must be set in $valueArr

  • return: True on success False in case of error
  • since: pk-08-02-02
  • access: public
bool deleteArray (string $table,  &$valueArr, [boolean $debug = False], array $valueArr)
  • string $table: name of the DBTABLE
  • array $valueArr: value array with FIELDNAME as Index
  • boolean $debug: show debug information
  • &$valueArr

Implementation of:
INFA_OCSP_DBOBJ::deleteArray()
deletes an existing row where the primary key must be set in $valueArr
deleteRows (line 1138)

deletes a row form the database note delKeys must have at least one key => value element

  • since: pk-07-08-04
boolean deleteRows (string $table, array $delKeys, [ $backup = True], [boolean $debug = False])
  • string $table
  • array $delKeys
  • boolean $debug
  • $backup
disconnect (line 80)

disconnect from the database

void disconnect ()
errorMsg (line 359)

echos the last error

void errorMsg ([string $msg = ""])
  • string $msg: addintinal message to echo
executeCmd (line 750)

executes a sql cmd

  • version: pk-04-10-14
  • todo: check $aCmd in secMode
void executeCmd (string $aCmd, [boolean $debug = False], [boolean $secMode = True])
  • string $aCmd: the cmd
  • boolean $debug: show debug info
  • boolean $secMode:

    test a aCmd - not used now

    return mixed mysql_query($aCmd,$this->myConnId)

fetchArray (line 612)
void fetchArray ( $aCursor, [ $useNames = True])
  • $aCursor
  • $useNames
freeCursor (line 598)
void freeCursor ( $aCursor)
  • $aCursor
getArray (line 559)

generates a query and returns an array of the resultset

limit <> a multidimensional array is returned (see queryArray) if limit = 1 a single array is returned (see quickQuery)

conditions: if the column starts with a ? the value is assumed to be an sql statement else column=slashedvalue(value) is added to the query

  • version: pk-07-09-08 '?' coll added
  • since: pk-07-06-29
  • access: public
array getArray (string $aTable, [array $conditions = NULL], [int $offset = 0], [int $limit = 0], [string $orderBy = ""], [boolean $debug = False])
  • string $aTable: (the table name)
  • array $conditions: (array(COLUMN => VALUE)) if VALUE does not starts with a '¿' t
  • int $offset
  • int $limit: (0 is unlimeted)
  • string $orderBy: (comma seperated list of fields to order)
  • boolean $debug

Redefinition of:
OCSP_DB::getArray()
generates a query and returns an array of the resultset

Implementation of:
INFA_OCSP_DBOBJ::getArray()
generates a query and returns an array of the resultset
getColumnDef (line 1573)

returns the database column definition to use in create table or alter column

  • version: pk-04-10-08
  • version: pk-04-01-11
  • version: pk-04-11-08
  • version: pk-05-11-09
  • version: pk-07-10-30
  • version: pk-07-09-19
  • since: pk-03-10-22
string getColumnDef (array $dbDesc, [boolean $debug = False])
  • array $dbDesc: Column array generated with DB_MYSQL::getDBTblDesc()
  • boolean $debug
getDBTblColNames (line 1527)

returns an array of table column names

  • since: pk-06-02-20
array getDBTblColNames (string $aTable, [boolean $debug = False])
  • string $aTable
  • boolean $debug
getDBTblDesc (line 1354)

returns an array with column description arrays for each column where column name is the array index

a column description array has the following elements

  • string ['TYPE'] (type of the column example varchar,int,...)
  • int ['LEN'] (length of the column if supported by type)
  • string ['FLAGS'] (mysql flags)
  • boolean ['AUTO_INCREMENT'] (does the column use auto values on insert)
  • boolean ['NULL'] (null allowed)
  • boolean ['PRIMARY_KEY'] (the column is part of the primary key)
  • boolean ['KEY'] (the column is part of a -none primary- key)
  • string ['COLNAME'] (the name of the column - same as array index should be)

  • version: pk-03-10-24
  • version: pk-05-01-12 php: function mysql_list_fields() is deprecated
  • version: pk-06-02-09 error handling
  • version: pk-07-08-04 ['TABLE'] added to the column desc
  • version: pk-08-03-11 use $dbTableDefinitions
array getDBTblDesc (strint $table, [bool $debug = False])
  • strint $table
  • bool $debug: pk-03-10-24

Redefinition of:
OCSP_DB::getDBTblDesc()
returns an array with column description arrays for each column where column name is the array index
getDBTblList (line 1440)

returns an array with all tables in the database

  • version: pk-05-01-12 (php: function mysql_list_tables() is deprecated)
array getDBTblList ([bool $debug = False])
  • bool $debug: since pk-03-10-25

Redefinition of:
OCSP_DB::getDBTblList()
returns an array with all tables in the database
getDBType (line 99)

returns the dbType

  • access: public
string getDBType ()

Redefinition of:
OCSP_DB::getDBType()
returns the database type

Implementation of:
INFA_OCSP_DBOBJ::getDBType()
returns the dbType
getErrorMsg (line 371)

returns the last mySQL error message

  • since: pk-05-08-08
string getErrorMsg ()
getErrorNo (line 382)

returns the last mySQL error nr

  • since: pk-05-08-08
int getErrorNo ()
getPrimaryKeys (line 1414)

returns an array with all primary key column names

  • since: pk-06-02-09
array getPrimaryKeys (string $aTbl, [boolean $debug = False])
  • string $aTbl
  • boolean $debug
getQueryArray (line 265)

returns an array with the main parts of an select the returned array has the following indexes

  • ['SELECT']
  • ['FROM']
  • ['WHERE']
  • ['ORDER']
  • ['GROUP']
  • ['LIMIT']

  • since: pk-06-09-28
array getQueryArray (string $query, [boolean $debug = False])
  • string $query
  • boolean $debug
getTimeStamp (line 1924)

returns the linux timestamp (mktime) of a date column

  • access: public
double getTimeStamp (stirng $aDateVal, [boolean $debug = True])
  • stirng $aDateVal
  • boolean $debug
initConn (line 239)

initiates the connect this is not required for mysql

boolean initConn ()
insert (line 802)

execute an insert statement and returns True or generated auto-key

inserts a new row with $aQuery returns the value of the auto_increment field or True in case of an error it returns False

  • return: key of auto-key or True on success False in case of error
  • version: pk-06-07-22 debug info
  • version: pk-06-10-30 no lock without a keyfld
int insert (string $query, [string $aTable = ""], [string $keyfld = ""], [boolean $withLock = True], [boolean $debug = False])
  • string $query: a Insert statement
  • string $aTable: name of the table to insert the column
  • string $keyfld: auto-key (autoincremnt column)
  • boolean $withLock: lock table during insert (to get the key)
  • boolean $debug: show debug information
insertArray (line 866)

creates an insert statement and returns $this::insert()

  • return: key of auto-key or True on success False in case of error
  • version: pk-05-01-13 debuginfos
  • version: pk-06-07-22 phpwarning
  • version: pk-07-08-02 adding $idFld param
  • see: DB_mySQL::insert() inserts a new row out of an array returns the value of the auto_increment field or True in case of an error it returns False
int insertArray (string $table, array $valueArr, [boolean $debug = False], [string $idFld = ""])
  • string $table: name of the table to insert
  • array $valueArr: key=>value array
  • boolean $debug: show debug information
  • string $idFld

Redefinition of:
OCSP_DB::insertArray()
inserts a new row out of an array

Implementation of:
INFA_OCSP_DBOBJ::insertArray()
inserts a valueArr into the table
logCmd (line 721)

logs sql command (SELECTS ARE NOT LOGGED)

if !empty($GLOBALS['PROJECT']['DBLOG']) the query is add to: $GLOBALS['PROJECT']['DBLOG'] logfile

if ((!empty($GLOBALS['PROJECT']['DBADMINLOG'])) && (strpos($mystring, $findme) !== False)) the query is add to: $GLOBALS['PROJECT']['DBADMINLOG'] logfile

  • version: pk-03-10-18
void logCmd ([strint $aQuery = ""])
  • strint $aQuery: the query
numOfRows (line 606)
void numOfRows ( $aCursor)
  • $aCursor
publicConnect (line 220)
void publicConnect ([ $conffile = ""], [ $keepConnection = True])
  • $conffile
  • $keepConnection
qs_getDateStmt (line 1823)

returns a Date object in string representation

Exceptions: if $aDateObj is NULL $this->qs_getNullStmt() is returned if $aDateObj in not an object $aDataObj is retured with or without slashes

  • version: pk-03-12-13
  • version: pk-06-08-08 sprintf as mktime returns on some (32bit) systems wrong values if the year is greater then 2037
  • version: pk-07-10-01 no need to require date class as it passed within a parameter
  • since: pk-03-10-25
string qs_getDateStmt (OCSP_DATE $aDateObj, [boolean $slashed = True])
  • OCSP_DATE $aDateObj
  • boolean $slashed: use slashes
qs_getLikeStmt (line 1851)

returns a sql statement for use in search

  • access: public
string qs_getLikeStmt (string $searchStr, [boolean $toUpper = False], [boolean $inline = True], [boolean $debug = False])
  • string $searchStr
  • boolean $toUpper: convert the searchStr to upper cases or leave it as is
  • boolean $inline: enclose the searchStr in placeholders (%search%)
  • boolean $debug

Implementation of:
INFA_OCSP_DBOBJ::qs_getLikeStmt()
returns a sql statement for use in search
qs_getNowStmt (line 1786)

returns the db NOW() statement for date/time values

  • since: pk-03-10-25
string qs_getNowStmt ()
qs_getNullStmt (line 1774)

returns the db NULL statement for NULL values

  • since: pk-03-10-25
string qs_getNullStmt ()
qs_getPassword (line 1762)

returns a password command $aValue

  • version: pk-04-09-28
  • since: pk-04-01-13
string qs_getPassword (string $aValue)
  • string $aValue
qs_getSlashedValue (line 1745)

returns $aValue with slashes to use to create query strings

  • version: pk-05-07-05 mysql_real_escape_string added
  • version: pk-06-09-11 strval added
  • since: pk-03-10-25
string qs_getSlashedValue (string $aValue)
  • string $aValue

Redefinition of:
OCSP_DB::qs_getSlashedValue()
returns $aValue with slashes to use to create query strings

Implementation of:
INFA_OCSP_DBOBJ::qs_getSlashedValue()
returns $aValue with slashes to use to create query strings
qs_getWhereClause (line 1718)

returns the where clause for a select

  • version: pk-08-06-03
  • since: pk-07-08-14
string qs_getWhereClause ([array $conditions = NULL], [boolean $debug = False])
  • array $conditions
  • boolean $debug
qs_getWhereIn (line 1887)

returns WHERE col IN($valArr)

  • version: pk-07-08-20
  • since: pk-07-06-15
  • access: public
string qs_getWhereIn (string $col, array $valArr, [boolean $valuesAreString = True])
  • string $col
  • array $valArr
  • boolean $valuesAreString

Redefinition of:
OCSP_DB::qs_getWhereIn()
returns WHERE col IN($valArr)
qs_ifNullStmt (line 1801)

returns the db IFNULL/nvl statement

  • since: pk-03-10-25
string qs_ifNullStmt (string $column, [string $default = ""])
  • string $column
  • string $default
query (line 400)

opens a cursor for a query

OCSP_CURSOR_mySQL query ([string $aQuery = ""], [boolean $secMode = True], [boolean $withErrMsg = False], [boolean $autoFree = True], [boolean $useBuffer = True])
  • string $aQuery: the sql query
  • boolean $secMode
  • boolean $withErrMsg
  • boolean $autoFree
  • boolean $useBuffer

Redefinition of:
OCSP_DB::query()
opens a cursor for a query
queryArray (line 495)

returns an array of table rows

if $keyFld == $valueFld a simple array is returned ( $array[]=$value )

if $keyFld != $valueFld a simple array is returned where $keyFld is used as index ( $array[$key]=$value )

if $valueFld == -1 a named 2 dimensonal array is returned ( $array[$key]=$row )

if $keyFld == -1 && $valueFld == -1 a 2 dimensonal array is returned ( $array[]=$row )

array queryArray (string $aQuery, [int $keyFld = 0], [int $valueFld = 0], [boolean $secMode = True], [boolean $debug = False])
  • string $aQuery: a sql select statement
  • int $keyFld: index of the key field in the select result (starts at 0)
  • int $valueFld: index of the value field in the select result (starts at 0)
  • boolean $secMode: check query whith DB_mySQL::checkQuery()
  • boolean $debug: show debug info

Redefinition of:
OCSP_DB::queryArray()
returns an array of table rows
quickQuery (line 436)

returns (a column) of the first row match

if $colNr > -1 the column value at position $colNr in the select statement is returned (NOTE: index starts at 0)

if $colNr < 0 a array is returend if $usNames the DB-column names are the index otherwise the index of the returned are is the number in the select order

mixed quickQuery (string $aQuery, [int $colNr = -1], [boolean $withErrMsg = False], [boolean $useNames = True], [boolean $secMode = True], [boolean $debug = False])
  • string $aQuery
  • int $colNr
  • boolean $withErrMsg
  • boolean $useNames
  • boolean $secMode
  • boolean $debug

Implementation of:
INFA_OCSP_DBOBJ::quickQuery()
returns (a column) of the first row match
replace (line 1121)

replace existing row or insert now if not exists

calls:

  1. return $this->replaceArray($table,$valueArr,$debug);

  • see: DB_mySQL::replaceArray()
  • deprecated: since pk-05-01-01
void replace (string $table, array $valueArr, [boolean $debug = False])
  • string $table: name of the DBTABLE
  • array $valueArr: value array with FIELDNAME as Index
  • boolean $debug: show debug information
replaceArray (line 931)

replace existing row or insert now if not exists

inserts a row or update an existing row all existing values not in $valueArr (assoc) will be handeld by db spezifaction see mysql Doc: http://www.mysql.com/doc/en/REPLACE.html

  • return: True on success False in case of error
  • version: pk-04-08-10
  • version: pk-05-12-28 set auto_increment column in valueArr on insert
bool replaceArray (string $table,  &$valueArr, [boolean $debug = False], array $valueArr)
  • string $table: name of the DBTABLE
  • array $valueArr: value array with FIELDNAME as Index
  • boolean $debug: show debug information
  • &$valueArr

Implementation of:
INFA_OCSP_DBOBJ::replaceArray()
replace existing row or insert now if not exists
resortTable (line 1246)

resorts orderfields in a table (remove gaps)

orderfields are integers from 1 to ... the are used to let the user change order

  • version: pk-05-07-26
  • version: pk-06-01-03
boolean resortTable (string $table, string $orderFld, [string $where = ""], [string $debug = False], [string $orderby = ""], [string $groupbyCol = ""], [int $startIdx = 1])
  • string $table: the table
  • string $orderFld: the order column
  • string $where: the where clause with the keyword WHERE do not add things like group by or limit ....
  • string $debug: show debug info
  • string $orderby: order by prepend (SELECT .... ORDER BY $orderby,$orderFld)
  • string $groupbyCol: restart index when col change
  • int $startIdx
server_info (line 1320)

returns the mysql server info()

  • since: pk-07-02-22
string server_info ()
tblExists (line 1476)

checks if a table exists

  • version: pk-03-10-30
  • version: pk-03-10-24
  • since: pk-03-10-21
bool tblExists (string $aTable, [boolean $debug = False])
  • string $aTable: table name
  • boolean $debug: since pk-03-10-24

Implementation of:
INFA_OCSP_DBOBJ::tblExists()
checks if a table exists
tblHasColumn (line 1549)

returns if a table has a certain column

  • since: pk-05-11-16
boolean tblHasColumn (string $table, string $colName, [boolean $debug = False])
  • string $table
  • string $colName
  • boolean $debug
truncateTable (line 1198)

truncates a table

  • todo: backup
  • access: public
void truncateTable (string $aTable, [boolean $backup = True], [ $debug = False])
  • string $aTable
  • boolean $backup
  • $debug

Redefinition of:
OCSP_DB::truncateTable()
truncates a table
updateArray (line 998)

updates $values in $aTable where $conditions

  • return: number of effekted rows
  • abstract:
int updateArray (string $aTable, array $conditions, array $values, [int $limit = 0], [boolean $debug = False])
  • string $aTable
  • array $conditions
  • array $values
  • int $limit
  • boolean $debug

Redefinition of:
OCSP_DB::updateArray()
updates $values in $aTable where $conditions

Implementation of:
INFA_OCSP_DBOBJ::updateArray()
updates $values in $aTable where $conditions

Inherited Methods

Inherited From OCSP_DB

 OCSP_DB::addColumn()
 OCSP_DB::checkColName()
 OCSP_DB::getArray()
 OCSP_DB::getDBTblDesc()
 OCSP_DB::getDBTblList()
 OCSP_DB::getDBType()
 OCSP_DB::getIndexedArray()
 OCSP_DB::getMyConfFile()
 OCSP_DB::getMyDBName()
 OCSP_DB::getOne()
 OCSP_DB::getRow()
 OCSP_DB::insertArray()
 OCSP_DB::isConnected()
 OCSP_DB::isInit()
 OCSP_DB::newDBConnect()
 OCSP_DB::qs_getSlashedValue()
 OCSP_DB::qs_getWhereIn()
 OCSP_DB::query()
 OCSP_DB::queryArray()
 OCSP_DB::truncateTable()
 OCSP_DB::updateArray()

Documentation generated on Thu, 08 Jan 2009 17:45:33 +0100 by phpDocumentor 1.4.0a2