<?php
ini_set('display_errors', 1);

function GetCat1arr(){
	$arrCat1 = array("Horses", "Dogs", "Equipment", "Buildings"); 

	return $arrCat1;
}
function GetFileContents($mFilePathName){
	$myfile = fopen($mFilePathName, "r") or die("Unable to open file!");
	$mContents = fread($myfile,filesize($mFilePathName));
	fclose($myfile);
	return $mContents;
}
function GetTable($sql) {
	include('/home4/horseweb/pvars/pvarsLog.php');
	try {
		$conn = new PDO(
			sprintf('mysql:host=%s; dbname=%s; charset=%s',
				$db_vars['host'],
				$db_vars['name'],
				$db_vars['charset']
				),
				$db_vars['username'],
				$db_vars['password']
			);
		$stmt = $conn->prepare($sql);
		$stmt->execute();
		$result = $stmt->fetchAll();
		$conn = null;        // Disconnect
	}
	catch(PDOException $e) {
	  echo $e->getMessage();
	}
	return $result;
	}
function GetID($sql) {
	include('/home4/horseweb/pvars/pvarsLog.php');
	try {
		$conn = new PDO(
			sprintf('mysql:host=%s; dbname=%s; charset=%s',
				$db_vars['host'],
				$db_vars['name'],
				$db_vars['charset']
				),
				$db_vars['username'],
				$db_vars['password']
			);
		$stmt = $conn->prepare($sql);
		$stmt->execute();
		if($row = $stmt->fetch(PDO::FETCH_BOTH)) {
			$mID = $row[0];
		}
		else {
			$mID = 0;
		}
		$conn = null;        // Disconnect
	}
	catch(PDOException $e) {
	  echo $e->getMessage();
	}
	return $mID;
	}

function fInsertInto($mQuery){
	include('/home4/horseweb/pvars/pvarsLog.php');
	$showText = $mQuery;
	//INSERT INTO `log` (`ID`, `UserID`, `logDate`, `cat1ID`, `cat2ID`, `cat3ID`, `content`) VALUES (NULL, '0', '2019-01-23', '1', '5', '6', 'Newt needs a hoof trim.')
	try {
		$conn = new PDO(
		sprintf('mysql:host=%s; dbname=%s; charset=%s',
			$db_vars['host'],
			$db_vars['name'],
			$db_vars['charset']
			),
			$db_vars['username'],
			$db_vars['password']
		);
		$stmt = $conn->prepare($mQuery);
		if ($stmt->execute()) {
			$showText = 'Record Inserted, ID = '.$conn->lastInsertId();
		}
		else {
			$showText = 'Record Insert ***FAILED**';
		}
		$conn = null;        // Disconnect
	}
	catch(PDOException $e) {
	  echo $e->getMessage();
	}
	return $showText;
}  

?>