Location: PHPKode > scripts > VSFlexGrid XP > vsflexgrid-xp/db.php
<?
/***********************************************************
* Class:        DB                                         *
* Version:      1.1                                        *
* Date:         September 2004                             *
* Author:       Agus Hariyanto                             *
* Copyright:    © Agus H                                   *
* Licence :     Free for non-commercial use                *
* email :       hide@address.com                         *
************************************************************/

class DB
{
	private $xfieldname;
	private $xvalue;
	private $xset;
	
	function __construct()
	{
		$this->xfieldname=array();
		$this->xvalue=array();	
	}
	
	public function TArray($fieldname,$value,$noarray)
	{
		$this->xfieldname[$noarray]=$fieldname;
		$this->xvalue[$noarray]="'".$value."'";
		$this->xset[$noarray]=$fieldname.'='."'".$value."'";
	}

	public function ClearTArray()
	{
		unset($this->xfieldname);
		unset($this->xvalue);
	}
	
	public function db_connect()
	{
	   $connect = mssql_pconnect('pakong','sa','malcolmx'); 
	   if (!$connect)
	      return false;
	   if (!mssql_select_db('stekpi'))
	      return false;
	   return $connect;
	}

	public function get_record($fieldname,$tablename,$filter=null,$groupby=null,$orderby=null)
	{
	  $conn = $this->db_connect(); 
	  if ($filter==null & $groupby==null & $orderby==null)
	  {
	  	$sql = "select $fieldname from $tablename";
	  }
	  if ($filter!=null & $groupby==null & $orderby==null)
	  {
	  	$sql = "select $fieldname from $tablename where $filter";
	  }
	  
	  if ($filter!=null & $groupby!=null & $orderby==null)
	  {
	  	$sql = "select $fieldname from $tablename where $filter group by $groupby";
	  }
	  
	  if ($filter!=null & $groupby!=null & $orderby!=null)
	  {
	  	$sql = "select $fieldname from $tablename where $filter group by $groupby order by $orderby";
	  }
	  
	  if ($filter==null & $groupby!=null & $orderby==null)
	  {
	  	$sql = "select $fieldname from $tablename group by $groupby";
	  }
	  
	  if ($filter!=null & $groupby!=null & $orderby==null)
	  {
	  	$sql = "select $fieldname from $tablename order by $orderby";
	  }
	  
	  if ($filter!=null & $groupby!=null & $orderby==null)
	  {
	  	$sql = "select $fieldname from $tablename where $filter group by $groupby";
	  }
	  
	  if ($filter!=null & $groupby==null & $orderby!=null)
	  {
	  	$sql = "select $fieldname from $tablename where $filter order by $orderby";
	  }
	  
	  if ($filter==null & $groupby!=null & $orderby!=null)
	  {
	  	$sql = "select $fieldname from $tablename where group by $groupby order by $orderby";
	  }  
	  $result=mssql_query($sql, $conn);	  
	  return $result;
	}
	
	public function del_record($tablename,$filter=null)
	{
		$conn=$this->db_connect();
		if ($filter==null)
		{
			$sql="delete $tablename";
		}
		else 
		{
			$sql="delete $tablename where $filter";
		}
		mssql_query($sql,$conn);
	}
	
	public function ins_record($tablename)
	{
		$conn = $this->db_connect(); 
		$fieldname=implode(',',$this->xfieldname);
		$value=implode(',',$this->xvalue);
		$sql="insert into $tablename($fieldname) values($value)";
		mssql_query($sql,$conn);
	}
	
	public function upd_record($tablename,$filter=null)
	{
		$conn = $this->db_connect(); 
		if ($filter==null)
		{
			$sql="update $tablename set ".implode(',',$this->xset);
		}
		else
		{
			$sql="update $tablename set ".implode(',',$this->xset)." where $filter";
		}
		mssql_query($sql,$conn);
	}
}
?>
Return current item: VSFlexGrid XP