Location: PHPKode > projects > Katropine DBmanager > dbmanager/controllers/controller.php
<?php
class Controller{
	public function __sqlresoult(){
		if(isset($_POST['sqlinport'])){
			return self::_sqlinport();
		}else if($_REQUEST['autosql'] == 'browse'){
			return self::_browse();
		}else if($_REQUEST['autosql'] == 'empty'){
			return self::_empty();
		}else if($_REQUEST['autosql'] == 'drop'){
			return self::_drop();
		}else if($_POST['sqlexe'] == 'yes'){
        echo 'FUCK';
        }
		return false;
	}
	
	private function _browse(){
		global $link;
		$bla['layout'] = 1;
		$obj = new Mysql_Data_Handler($link,false);
		//======================================== pagign ========================================
		$page = $_REQUEST['page'];
		$page = (empty($page))? 1 : $page;
		$rp = 30; // how meny resoults per page
		$total = $obj->__dataScalar("SELECT COUNT(id) FROM ".$_REQUEST['table'].";");
		$limit = 5;
		
		$start = (($page-1) * $rp);
		$sql = 'SELECT * FROM '.$_REQUEST['table'].' LIMIT '.$start.','.$rp.';';
		$bla['data'] = $obj->__dataTable($sql );
		$bla['pg'] = paging($page,$rp,$total,$limit); 
		//========================================================================================
		$bla['total'] = $total;
		$bla['sql'] = $sql;
		$bla['mysql_num_rows'] = $obj->__dataNum_rows();
		$bla['mysql_query_time'] = $obj->query_time;
		$bla['error'] =  $obj->error;
		$bla['error_msg'] =  $obj->errormsg;
		$bla['sql_action'] = "select";
		return $bla;
	}
	
	private function _empty(){
		global $link;
		$bla['layout'] = 1;
		$sql = 'DELETE FROM '.$_REQUEST['table'].';';
		$obj = new Mysql_Data_Handler($link,false);
		$bla['data'] = $obj->__dataTable($sql);
		$bla['sql'] = $sql;
		$bla['mysql_num_rows'] = $obj->__dataNum_rows();
		$bla['mysql_query_time'] = $obj->query_time;
		$bla['error'] =  $obj->error;
		$bla['error_msg'] =  $obj->errormsg;
		$bla['sql_action'] = "empty";
		return  $bla;
	}
	
	private function _drop(){
		global $link;
		$bla['layout'] = 1;
		$sql = 'DROP TABLE '.$_REQUEST['table'].';';
		$obj = new Mysql_Data_Handler($link,false);
		$bla['data'] = $obj->__dataTable($sql);
		$bla['sql'] = $sql;
		$bla['mysql_num_rows'] = $obj->__dataNum_rows();
		$bla['mysql_query_time'] = $obj->query_time;
		$bla['error'] =  $obj->error;
		$bla['error_msg'] =  $obj->errormsg;
		$bla['sql_action'] = "drop";
		return $bla;
	}
	
	private function _sqlinport(){
		global $link;
			$obj = new Mysql_Data_Handler($link,false);
			$sql = $_POST['sqlinport'];
			
			/*
			 * check lenght of sql/s
			 */
			$len = strlen($sql);
			$i=0;
			$new_sql = '';
			/*
			 * search for delimeter of single SQL ignoring it within ''
			 */
			for($j = 0; $j <=$len; $j++){
				
				if($sql[$j] == "'"){
					$i+=1;
					if($i==2){
						$i=0;
					}
				} 
				/*
				 * form single sql till delimeter [;] 
				 * and make array of isolated SQL/s
				 */
				$new_sql .= $sql[$j];
				if($i == 0 && $sql[$j] == ';'){
					$sql_array[] = $new_sql;
					$new_sql = '';
				}
			}
			
			
			if(count($sql_array) > 1){
				
				foreach ($sql_array as $key => $val) {
					if($val != ""){
						$obj->__dataTable($val);
						$data[] = "[SQL No: ".$key." DONE]...".$val;
					}
				}
				$bla['layout'] = 2;
				$bla['data'] = $data;
			}else{
				$bla['layout'] = 1;
				$bla['data'] = $obj->__dataTable($sql);
			}
			$bla['sql'] = $sql;
			$bla['mysql_num_rows'] = $obj->__dataNum_rows();
			$bla['mysql_query_time'] = $obj->query_time;
			$bla['error'] =  $obj->error;
			$bla['error_msg'] =  $obj->errormsg;
			$bla['sql_action'] = "inport";
			return $bla;
	}
}
?>
Return current item: Katropine DBmanager