From 0a4f50e5651bf4e02e01d87332b5cdb4fc897238 Mon Sep 17 00:00:00 2001 From: Gerald Simane Date: Wed, 24 Feb 2010 09:26:23 +0000 Subject: [PATCH] --- include/basis_db.class.php | 80 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) diff --git a/include/basis_db.class.php b/include/basis_db.class.php index 34bf8bfc1..4f6613279 100644 --- a/include/basis_db.class.php +++ b/include/basis_db.class.php @@ -29,6 +29,86 @@ abstract class db extends basis } + function creatSQL($pArt='select',$pDistinct=false,$pFields='',$pTable='',$pWhere='',$pOrder='',$pLimit='',$pSql='') + { + // Init + $this->errormsg=''; +## echo "
$pArt,$pDistinct,$pFields,$pTable,$pWhere,$pOrder,$pLimit,$pSql"; + $result=false; + // Check Parameter + $sql=(!is_null($pSql)?trim($pSql):''); + $art=(!is_null($pArt)?trim($pArt):''); + $distinct=($pDistinct?true:false); + $fields=(!is_null($pFields)?trim($pFields):''); + $table=(!is_null($pTable)?trim($pTable):''); + $where=(!is_null($pWhere)?trim($pWhere):''); + $order=(!is_null($pOrder)?trim($pOrder):''); + $limit=(is_numeric($pLimit)?$pLimit:''); + + if (empty($sql) && empty($art)) + { + $this->errormsg='die SQL Art fehlt!'; + return $result; + } + else if (empty($sql) && empty($table)) + { + $this->errormsg='die SQL Tabelle fehlt!'; + return $result; + } + + if (empty($sql)) + { + // DB Abfrage zusammenbauen + $sql.=$art. ' '; + if ($art=='select') + $sql.=($distinct?' distinct ':''); + $sql.=($fields?$fields:' * '); + $sql.=($table?' from '.trim($table).' ':''); + if (!empty($where) && strstr('where',strtolower($where))) + $sql.=($where?' '.trim($where).' ':''); + else if (!empty($where)) + $sql.=($where?' where '.trim($where).' ':''); + + switch ($art) + { + case 'select': + if (strstr('order',strtolower($where))) + $sql.=($order?trim($order).' ':''); + else + $sql.=($order?' order by '.trim($order).' ':''); + if (strstr('limit',strtolower($where))) + $sql.=($limit?trim($limit).' ':''); + else + $sql.=($limit?' limit '.trim($limit).' ':''); + break; + default: + $this->errormsg='die SQL Art '.$art.' wird nicht unterstuetzt !'; + return $result; + break; + } + } +##echo "
$sql
"; + if (!$results=$this->db_query($sql)) + { + $this->errormsg=$this->db_last_error(); + return false; + } + + if ($art!='select' && empty($sql) ) + return true; + + if (!$num=$this->db_num_rows($results)) + { + $this->errormsg='keine Daten gefunden'; + return false; + } + // Lesen aller DB Daten + $rows=array(); + while($row = $this->db_fetch_object($results)) + $rows[]=$row; + return $rows; + } + require_once(dirname(__FILE__).'/'.DB_SYSTEM.'.class.php'); ?> \ No newline at end of file