Source for file OCSP_DB.phpclass
Documentation is available at OCSP_DB.phpclass
* Class file OCSP_DB.phpclass
* @project Open CSP-Management
* @author Peter Krebs (pk) <pitlinz@users.sourceforge.net>
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
* @version $Id: OCSP_DB.phpclass,v 1.24 2008/11/20 17:02:47 peterkrebs Exp $
* @requires ../common/pcf.phpinc [OCSP]
* @requires ./db/db.phpinc [OCSP]
* ---------------------------------------------------
* common settings and requirements
require
__OCSP_PHPINCPATH__ .
"common" .
_OCSP_DIRSEP_ .
"pcf.phpinc";
require
__OCSP_PHPINCPATH__ .
"db" .
_OCSP_DIRSEP_ .
"db.phpinc";
/** ---------------------------------------------------
* @project Open CSP-Management
* @author Peter Krebs (pk) <pitlinz@users.sourceforge.net>
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
/** -----------------------------------------------------
/** -----------------------------------------------------
/** -----------------------------------------------------
* @var string $myConfFile
* @var boolean $iam_connected
* @var boolean $iam_initialized
* var boolean $debugInsert
* METHODS _____________________________________________
/** -----------------------------------------------------
* connects to the default database
* @param string $confFile
* @param boolean $reconnect (init a new DB object even we already have one)
* @global array $OCSP_CONF
* @global array $OCSP_OBJ
function &newDBConnect($confFile=
"",$reconnect=
FALSE,$debug=
FALSE)
echoDebugLine(__FILE__
,__LINE__
,"we already have an established connection");
if ($debug) echoDebugLine(__FILE__
,__LINE__
,"using global database connection");
if (!$OCSP_OBJ['USRDB']->isConnected())
$OCSP_OBJ['USRDB']->connet($confFile,$b_asPublic,FALSE,$debug);
return $OCSP_OBJ['USRDB'];
return $OCSP_OBJ['USER']->getMyDBObj(FALSE,$confFile,TRUE,$debug);
$confFile=
$OCSP_CONF['PROJECTPATH'].
$OCSP_CONF['DBCONFFILE'];
if (!isset
($DBCONF['CLASS']) ||
empty($DBCONF['CLASS']))
$DBCONF['CLASS'] =
"OCSP_DB_mySQL";
$DBCONF['INCLUDE'] =
$GLOBALS['OCSP']['PHPINCPATH'].
"db/OCSP_DB_mySQL.phpclass";
if (!empty($DBCONF['INCLUDE']))
require_once $GLOBALS['OCSP']['PHPINCPATH'].
"common/pcf_templates.phpinc";
if ($debug) echoDebugLine(__FILE__
,__LINE__
,"loading DB-ClassFile ".
$tsr_inc);
require_once $GLOBALS['OCSP']['PHPINCPATH'].
"db/".
$DBCONF['CLASS'].
".phpclass";
$str_cmd=
"\$o_db=new ".
$DBCONF['CLASS'].
"();";
if ($debug) echoDebugLine(__FILE__
,__LINE__
,"generating db object ".
$str_cmd);
$o_db->connect($confFile,$b_asPublic,FALSE,$debug);
if ($debug) echoDebugLine(__FILE__
,__LINE__
,"DBMS_TABLEOBJ::dbConnect(reconnect) NOT IMPLEMENTED".
$tsr_cmd);
/** -----------------------------------------------------
* getter & setter methods
* returns the database type
* can also be called without object OCSP_DB::getMyConfFile()
* if $this->myConfFile is empty the global dbConffile is returned
* @param boolean $fromUser try to get the conffile from the current user
function getMyConfFile($fromUser=
True,$fromSession=
True,$debug=
False)
if ($str_ret =
$obj_user->getDBConfFile(False,$debug))
if ($debug) echoDebugLine(__FILE__
,__LINE__
,"returning users conffile: ".
$str_ret);
if ($debug) echoDebugLine(__FILE__
,__LINE__
,"returning session conffile: ".
$str_ret);
if ($debug) echoDebugLine(__FILE__
,__LINE__
,"returning DBCONFFILE conffile: ".
$str_ret);
if ($debug) echoDebugLine(__FILE__
,__LINE__
,"\$str_confFile: " .
$str_confFile);
if ($debug) echoDebugLine(__FILE__
,__LINE__
,"returning PROJ_CONFPATH . DBTYPE . conf conffile: ".
$str_confFile);
if ($debug) echoDebugLine(__FILE__
,__LINE__
,"\$str_confFile: " .
$str_confFile);
if ($debug) echoDebugLine(__FILE__
,__LINE__
,"returning PROJ_CONFPATH . DBTYPE . conf conffile: ".
$str_confFile);
if ($debug) echoDebugLine(__FILE__
,__LINE__
,"ERROR: could not find a database configuration for ".
get_class($this));
/** -----------------------------------------------------
* 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)
* @param string $aTable (the table name)
* @param array $conditions (array(COLUMN => VALUE)
* @param int $limit (0 is unlimeted)
* @param string $orderBy (comma seperated list of fields to order)
function getArray($aTable,$conditions,$offset=
0,$limit=
0,$orderBy=
"",$debug=
false)
* generates a query and returns an array of the resultset with $idxCol as index and $valCols as values
* if $valCols is an array of column names this columns are added as array to the returned array
* if $valCols is empty the complete row is added to the return array
* else $row[$valCols] is added to the return (simple array)
* limit <> a multidimensional array is returned (see queryArray)
* if limit = 1 a single array is returned (see quickQuery)
* @param string $aTable (the table name)
* @param array $conditions (array(COLUMN => VALUE)
* @param int $limit (0 is unlimeted)
* @param string $orderBy (comma seperated list of fields to order)
public function getIndexedArray($aTable,$conditions,$idxCol,$valCols=
null,$offset=
0,$limit=
0,$orderBy=
"",$debug=
FALSE)
if ($arr_result =
$this->getArray($aTable,$conditions,$offset,$limit,$orderBy,$debug))
foreach($arr_result as $arr_row)
if (!isset
($arr_row[$idxCol]))
$arr_ret[$arr_row[$idxCol]] =
array();
foreach($valCols as $str_col)
$arr_ret[$arr_row[$idxCol]][$str_col] =
$arr_row[$str_col];
$arr_ret[$arr_row[$idxCol]] =
$arr_row;
$arr_ret[$arr_row[$idxCol]] =
$arr_row[$valCols];
* Runs the query provided and returns the data from the first column of the first row then frees the result set.
return $this->quickQuery($query,0);
* returns the first row matching $filter
* @version pk-08-02-15 filter type like (~) added
function getRow($table,$filter,$debug=
false)
$str_query=
"SELECT * FROM ".
$table;
foreach($filter as $str_col =>
$mix_val)
if (substr($str_col,0,1)==
"?")
$str_query.=
$str_whereAnd.
$mix_val;
} else if (substr($str_col,0,1)==
"~") {
$str_query .=
$str_whereAnd .
substr($str_col,1) .
" " .
$this->qs_getLikeStmt($mix_val);
if ($debug) echoDebugLine(__FILE__
,__LINE__
,"Query: ".
$str_query);
return $this->quickQuery($str_query);
* opens a cursor for a query
* @param string $aQuery the sql query
* @param boolean $secMode
* @param boolean $withErrMsg
* @param boolean $autoFree
* @param boolean $useBuffer
function query($aQuery=
"",$secMode=
True,$withErrMsg=
False,$autoFree=
True,$useBuffer=
True)
throw
new Exception("abstract method not implemented:" .
get_class($this) .
"::" . __FUNCTION__
);
* returns an array of table rows
* if $keyFld == $valueFld
* a simple array is returned
* if $keyFld != $valueFld
* a simple array is returned where $keyFld is used as index
* ( $array[$key]=$value )
* a named 2 dimensonal array is returned
* if $keyFld == -1 && $valueFld == -1
* a 2 dimensonal array is returned
* @param string $aQuery a sql select statement
* @param int $keyFld index of the key field in the select result (starts at 0)
* @param int $valueFld index of the value field in the select result (starts at 0)
* @param boolean $secMode check query whith DB_mySQL::checkQuery()
* @param boolean $debug show debug info
function queryArray($aQuery,$keyFld=
0,$valueFld=
0,$secMode=
True,$debug=
False)
throw
new Exception("abstract method not implemented:" .
get_class($this) .
"::" . __FUNCTION__
);
* inserts a new row out of an array
* returns the value of the auto_increment field (idFld) or True
* in case of an error it returns False
function insertArray($table,$valueArr,$debug=
False,$idFld=
"")
throw
new Exception("abstract method not implemented:" .
get_class($this) .
"::" . __FUNCTION__
);
* updates $values in $aTable where $conditions
* @param array $conditions
* @return int number of effekted rows
function updateArray($aTable,$conditions,$values,$limit=
0,$debug=
false)
throw
new Exception("abstract method not implemented:" .
get_class($this) .
"::updateArray");
throw
new Exception("abstract method not implemented:" .
get_class($this) .
"::truncateTable");
/** -----------------------------------------------------
* returns $aValue with slashes to use to create query strings
* return "'".str_replace("'","\'",strval($aValue))."'";
* returns WHERE col IN($valArr)
* @param boolean $valuesAreString
public abstract function qs_getWhereIn($col,$valArr,$valuesAreString=
True);
// ------------------------------------------------------
// ------------------------------------------------------
* returns a valid column name
* adds a column to a table
public function addColumn($aTable,$colName,&$dbDesc,$debug=
False)
throw
new Exception("method not implemented: " .
get_class($this) .
"::addColumn()");
* returns an array with all tables in the database
throw
new Exception("method not implemented: " .
get_class($this) .
"::getDBTblList()");
* 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)
* @param bool $debug pk-03-10-24
throw
new Exception("method not implemented: " .
get_class($this) .
"::getDBTblDesc()");
Documentation generated on Thu, 08 Jan 2009 17:45:28 +0100 by phpDocumentor 1.4.0a2