<?php
// getTableData - Retrieve Specified Fields from Requested Table
// echo "test";
$mFunction  		= $_GET['function'];
$mConnect   		= $_GET['connection'];
$mUser				= $_GET['user'];
$mPwd				= $_GET['pword'];
$mHost              = $_GET['host'];
$mDbName			= $_GET['dbase'];
$mTableName 		= $_GET['table'];
$mFilter			= $_GET['filter'];
$mReturnFields		= $_GET['returnfields'];

if (($mFunction != null) && ($mFunction == "update"))
{	
	$mConnection=mysqli_connect($mHost,$mUser,$mPwd,$mDbName) or
	exit("Connect failed: ".mysqli_connect_errno()." : ". mysqli_connect_error());
	$mDataQuery = "UPDATE ".$mDbName.".".$mTableName." SET ".$mReturnFields." WHERE ".$mFilter;
	$mData = mysqli_query($mConnection,$mDataQuery);
	mysqli_query($mConnection,$mQueryString);	
	if (mysqli_connect_errno())
	{
		echo("0" . ":" . $mQueryString);
	}
	else
	{
		echo("1:".$mDataQuery);
	}
	mysqli_close($mConnection);	
	return;
}

$mConnection=mysqli_connect($mHost,$mUser,$mPwd,$mDbName) or
	exit("Connect failed: ".mysqli_connect_errno()." : ". mysqli_connect_error());
$mDataQuery = "SELECT ".$mReturnFields." FROM ".$mDbName.".".$mTableName." WHERE ".$mFilter;
$mData = mysqli_query($mConnection,$mDataQuery);
$i = 0;
	while($mRow = mysqli_fetch_assoc($mData)) 
	{
		$mSQLData[] =($mRow);
		$i++;
	}
	mysqli_close($mConnection);
	If ($i > 0)
	{
		$mReturnData[] =(array_merge(array("status" => "OK   - "),$mSQLData));
	}
	else
	{
		$mReturnData[] = array("status" => "FAIL - No ".$mTableName." Records");
	}
	echo json_encode($mReturnData);			
	return;
?>