<?php
error_reporting(E_ALL ^E_NOTICE);
$username = "learning_admin"; 
$password = "DCn(rc&N6=5B"; 
$host = "localhost"; 
$dbname = "learning_joomla";
$options = array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8');
try 
{ 
	$db = new PDO("mysql:host={$host};dbname={$dbname};charset=utf8", $username, $password, $options); 
} 
catch(PDOException $ex){ die($ex->getMessage()); }
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); 
$db->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC); 
$db->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true); 
if(function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc()) 
{ 
	function undo_magic_quotes_gpc(&$array) 
	{ 
		foreach($array as &$value) 
		{ 
			if(is_array($value)) 
			{ 
				undo_magic_quotes_gpc($value); 
			} 
			else 
			{ 
				$value = stripslashes($value); 
			} 
		} 
	} 
	undo_magic_quotes_gpc($_POST); 
	undo_magic_quotes_gpc($_GET); 
	undo_magic_quotes_gpc($_COOKIE); 
}
function dosql($query, $data = "", $bindParams = false)
{
	global $db;
	try
	{ 
		$stmt = $db->prepare($query);
		if ($bindParams)
		{
			if ($data && is_array($data))
			{
				$binds = array("string" => PDO::PARAM_STR,
				"object" => PDO::PARAM_STR,
				"double" => PDO::PARAM_STR,
				"NULL" => PDO::PARAM_INT,
				"integer" => PDO::PARAM_INT);
				foreach ($data as $key => $value)
				{
					$stmt->bindValue($key, $value, $binds[gettype($value)]);
				}
			}
			$stmt->execute();
			$stmt->setFetchMode(PDO::FETCH_ASSOC);
		}
		else
		{
			$result = $data? $stmt->execute($data) : $stmt->execute();
		}
		return $stmt;
	} 
	catch(PDOException $ex) 
	{ 
		die($ex);
	}
}
dosql("INSERT INTO `lrns_games` (`game_name`, `player`, `date`, `game_percent`, `ip`) VALUES(:game_name, :player, :date, :game_percent, :ip)", array(":game_name" => $_GET["game_name"], ":player" => $_GET["player"], ":game_percent" => rtrim($_GET["game_percent"], '%'), ":date" => date('Y-m-d H:i:s'), ":ip" => getenv("REMOTE_ADDR")));
?>