<?php
/**
 * Open Source - Content Managment System
 * Next Generation v2
 * @Coder:  Mutzii
 * @copyright  Copyright (c) 2012-2013 by Mutzii
 * File: sql.class.php
 * @Description:  SQL Commands  
 */ 

class SQL
{
   
     public function CreateDatabase($database)
	 {
	   $sql = 'CREATE DATABASE '.$database.'';
	   return $sql;
	 }


      // Datenbank Einträge schreiben .. für Registierungs Seiten.
     public function insert($table,$column,$cell)    
       {
	      $sql = '';
	      $column_size = count($column); // Spalten Anzahl
	      $cell_size   = count($cell);  // Zellen Anzahl
           
		        $sql .= "INSERT INTO `$table` (";
			 if(is_array($column)){
			 for ($i = 0; $i <= $column_size-1; $i++) {
                  
				  if($i == $column_size-1){
				     $sql .= "`$column[$i]`)";
				  }else{
				     $sql .= "`$column[$i]` ,";
				  }
               }
			  }
			    
				$sql .= " VALUES( ";
			   if(is_array($cell)){
               for ($i = 0; $i <= $cell_size-1; $i++) {
                  
				  if($i == $cell_size-1){
				     $sql .= "'$cell[$i]');";
				  }else{
				     $sql .= "'$cell[$i]' ,";
				  }
               }
			   }
			   
			  return $sql;
			
			   
				 
       }
	   	
	  public function updatedouble($table,$column,$edit,$primary,$key)
	   {
		    $sql = "UPDATE `$table` SET `$column` = $edit WHERE `$primary` = '$key';"; 
			
	     return $sql;
	   }  
 
	  public function updateint($table,$column,$edit,$primary,$key)
	   {
		    $sql = "UPDATE $table SET $column = $edit WHERE `$primary` = '$key';"; 
			
	     return $sql;
	   }
	   
	  public function updatechar($table,$column,$edit,$primary,$key)
	   {
		    $sql = "UPDATE `$table` SET $column = '$edit' WHERE `$primary` = '$key';"; 
			
	     return $sql;
	   }
	   
	   
	  public function delete($table,$primary,$key)
	   {
	   
	       $sql = "DELETE FROM $table WHERE `$primary` = $key;";
	   
	     return $sql;
	   }
	   
	   public function search($table,$primary,$key)
	   {
	      $sql = "SELECT * FROM $table WHERE `$primary` = '$key';";
		    
	      return $sql;
	   }
	   
	   public function select_limit($table,$limit = 0,$entries = 30)
	   {
	      if(is_numeric($limit) && is_numeric($entries))
		    {
	           if($limit <= $entries){$limit_second = $entries;}
			   if($limit >= $entries){$limit_second = $limit+$entries;}
			     
			        $sql = "SELECT * FROM $table LIMIT $limit,$limit_second;";
		    }
	      return $sql;
		  
	   }

           public function select($table){
              return $sql = "SELECT * FROM $table";
           }
	   
	   public function sortieren($table,$column,$limit = 0,$entries = 30)
	   {
	     if(is_numeric($limit) && is_numeric($entries))
		    {
	           if($limit <= $entries){$limit_second = $entries;}
			   if($limit >= $entries){$limit_second = $limit+$entries;}
	      
		            $sql = "SELECT * FROM '$table' ORDER BY '$column' ASC LIMIT '$limit','$limit_second';";
	        }
	      return $sql;
	   }
	   
	   
	   public function query($sql)
	    {	
	      if(!$result = mysql_query($sql))
		     {
			     return die(mysql_errno() . ": " . mysql_error(). "\n"); 
			 }else{
                 return $result;
             }		   
	    }
}
?>
