<?php
/**
 * Open Source - Content Managment System
 * Next Generation v2
 * @Coder:  Mutzii
 * @copyright  Copyright (c) 2012-2013 by Mutzii
 * File: mysql.class.php
 * @Description:  Verbindung zur MySQL Datenbank aufbauen.
  
 */

class MySQL
{
   var $server;
   var $user;
   var $pass;
   var $db;
   var $connect;


    public function MySQL($daten,$connect = false)
    {
       if(is_array($daten)){
	   
	       $this->server  = $daten[0];
		   $this->user    = $daten[1];
		   $this->pass    = $daten[2];
		   $this->db      = $daten[3];
		   $this->connect = $daten[4];	
          
		  if($connect != false){
            $this->verbinden($this->connect); 
          }	
		  
	   }

    }	
   
    public function Connect()
	{
	   if(!$result = mysql_connect($this->server,$this->user,$this->pass)){
	        die('Fehler: MySQL Verbindung Fehlgeschlagen.' . mysql_error());
	   }
	}
	
	public function select_db($default = false)
	{
	  if($default == false){
	      mysql_select_db($this->db);
	  }else{
	      mysql_select_db($default);
	  }
	}
	
	public function sql_file_update($file)
	{
	   $file_content = file($file);
	   $query = "";
					foreach($file_content as $sql_line){
						if(trim($sql_line) != "" && strpos($sql_line, "--") === false){
						$query .= $sql_line;
						    if (substr(rtrim($query), -1) == ';'){
								$result = mysql_query($query)or die(mysql_error());
								$query = "";
							}
						}
					}
	}
 
    public function verbinden($connect = false)
    {

	       if(!$connect == false){
           if(!$result = mysql_connect($this->server,$this->user,$this->pass)) {
                die('Fehler: MySQL Verbindung Fehlgeschlagen.' . mysql_error());
           }else{

                   if(mysql_select_db($this->db))
                    {
                         return true;
                         
                    }else{
                      
                        die('Fehler: MySQL Datenbank existiert nicht.' . mysql_error());
                        return false;
                      
                    }
           }
		   }
	
	
	}


}
?>