From b99a29ac867298c648208ab558136f6351396ecb Mon Sep 17 00:00:00 2001
From: Przemek Grondek <github@nerull7.info>
Date: Tue, 30 Sep 2014 14:38:41 +0200
Subject: [PATCH] Added Raw SQL Query

---
 c.php | 29 +++++++++++++++++++++++++++--
 1 file changed, 27 insertions(+), 2 deletions(-)

diff --git a/c.php b/c.php
index 248eb25..288e38c 100644
--- a/c.php
+++ b/c.php
@@ -59,8 +59,28 @@
 		}
 		
 		function query($query){
-			$result = mysql_query($query);
-			return $result;
+			$result_id = mysql_query($query);
+
+			if( !$result_id ){
+	                    echo mysql_error()."\n";
+        	        } else if ( $info = mysql_info() ){
+				echo $info;
+			} else { 
+                	    	echo OK."\n";
+	                
+
+				$numOfCols = mysql_num_fields($result_id);
+				if($numOfCols > 0 ) {
+		                        for($i=0;$i<$numOfCols;$i++)
+	        	                        $field[$i] = mysql_field_name($result_id, $i);
+
+	
+					echo json_encode($field)."\n";
+					for($i=0;$row=mysql_fetch_row($result_id);$i++)
+	                        	        $result[$i] = $row;
+					echo json_encode($result);
+				}
+			}
 		}
 		
 		function disconnect(){
@@ -176,6 +196,9 @@
 		}
 	}
 
+	// DEBUG!!!
+	// $_POST = $_GET;
+
 	$action 	= $_POST['a'];
 	
 	$server		= 'localhost';
@@ -222,6 +245,8 @@
 	        break;
 		case "query":
 			$con->connect();
+			if(isset($database))
+				$con->selectDb($database);
 			$con->query($query);
 			break;
 		case "getrows":