<?php

/** This PHP makes "download" files for database see. JKANetwork and DBWrapper involved...*/

$type = $_POST['dbcode_type']; //Database (SQLite3,MySQL...)
$dbHost = $_POST['dbcode_host']; //Where it is.

switch($type){
	case 'sqlite3':
		$file = '<?php
				$conn = new SQLite3("'.$dbHost.'",SQLITE3_OPEN_READONLY) or die("FAIL");
				die("OK");
				?>';
	break;
	case 'mysqli':
		$dbUser = $_POST['dbcode_user'];
		$dbPass = $_POST['dbcode_pass'];
		$file = '<?php
			mysqli_connect("'.$dbHost.'","'.$dbUser.'","'.$dbPass.'",) or die("FAIL");
			die("OK");
			?>';
	break;
	case 'pgsql':
		$dbUser = $_POST['dbcode_user'];
		$dbPass = $_POST['dbcode_pass'];
		$dbDb = $_POST['dbcode_db'];
		$file = '<?php
			pg_connect("host='.$dbHost.' dbname='.$dbDb.' user='.$dbUser.' password='.$dbPass.'") or die ("FAIL");
			die("OK");
			?>';
	break;
}

header ("Content-Disposition: attachment; filename=dbtest.php");
header ("Content-Type: text/php");
print $file;