adds a column to a table
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
checks a query string if it's save to use
string
checkQuery
(string $aQuery, [int $type = PQT_SELECT], [boolean $debug = False])
-
string
$aQuery
-
int
$type: PQT_[querytype]
-
boolean
$debug
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
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
connects to the database
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
void
createTable
( $tblName, $cols, [ $debug = False])
deletes an existing row where the primary key must be set in $valueArr
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
deletes a row form the database note delKeys must have at least one key => value element
boolean
deleteRows
(string $table, array $delKeys, [ $backup = True], [boolean $debug = False])
-
string
$table
-
array
$delKeys
-
boolean
$debug
-
$backup
disconnect from the database
void
disconnect
()
echos the last error
void
errorMsg
([string $msg = ""])
-
string
$msg: addintinal message to echo
executes a sql cmd
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)
void
fetchArray
( $aCursor, [ $useNames = True])
void
freeCursor
( $aCursor)
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
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
returns the database column definition to use in create table or alter column
string
getColumnDef
(array $dbDesc, [boolean $debug = False])
-
array
$dbDesc: Column array generated with DB_MYSQL::getDBTblDesc()
-
boolean
$debug
returns an array of table column names
array
getDBTblColNames
(string $aTable, [boolean $debug = False])
-
string
$aTable
-
boolean
$debug
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)
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
returns an array with all tables in the database
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
returns the last mySQL error message
string
getErrorMsg
()
returns the last mySQL error nr
int
getErrorNo
()
returns an array with all primary key column names
array
getPrimaryKeys
(string $aTbl, [boolean $debug = False])
-
string
$aTbl
-
boolean
$debug
returns an array with the main parts of an select the returned array has the following indexes
- ['SELECT']
- ['FROM']
- ['WHERE']
- ['ORDER']
- ['GROUP']
- ['LIMIT']
array
getQueryArray
(string $query, [boolean $debug = False])
-
string
$query
-
boolean
$debug
returns the linux timestamp (mktime) of a date column
double
getTimeStamp
(stirng $aDateVal, [boolean $debug = True])
-
stirng
$aDateVal
-
boolean
$debug
initiates the connect this is not required for mysql
boolean
initConn
()
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
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
creates an insert statement and returns $this::insert()
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
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
void
logCmd
([strint $aQuery = ""])
-
strint
$aQuery: the query
void
numOfRows
( $aCursor)
void
publicConnect
([ $conffile = ""], [ $keepConnection = True])
-
$conffile
-
$keepConnection
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
string
qs_getDateStmt
(
OCSP_DATE $aDateObj, [
boolean $slashed =
True])
-
OCSP_DATE
$aDateObj
-
boolean
$slashed: use slashes
returns a sql statement for use in search
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
returns the db NOW() statement for date/time values
string
qs_getNowStmt
()
returns the db NULL statement for NULL values
string
qs_getNullStmt
()
returns a password command $aValue
string
qs_getPassword
(string $aValue)
returns the where clause for a select
string
qs_getWhereClause
([array $conditions = NULL], [boolean $debug = False])
-
array
$conditions
-
boolean
$debug
returns WHERE col IN($valArr)
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)
returns the db IFNULL/nvl statement
string
qs_ifNullStmt
(string $column, [string $default = ""])
-
string
$column
-
string
$default
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
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
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 existing row or insert now if not exists
calls:
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
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
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
resorts orderfields in a table (remove gaps)
orderfields are integers from 1 to ... the are used to let the user change order
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
returns the mysql server info()
string
server_info
()
checks if a table exists
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
returns if a table has a certain column
boolean
tblHasColumn
(string $table, string $colName, [boolean $debug = False])
-
string
$table
-
string
$colName
-
boolean
$debug
truncates a table
void
truncateTable
(string $aTable, [boolean $backup = True], [ $debug = False])
-
string
$aTable
-
boolean
$backup
-
$debug
Redefinition of:
- OCSP_DB::truncateTable()
- truncates a table
updates $values in $aTable where $conditions
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()