<?php
class Conexion {
	public function conectar(){
		// Server local WEB
		// $user = 'sa';
		// $password = 'AbC123*-';
		// $host = '192.249.53.231';
		// $dbname = 'posmercadoweb';

		// Server local
		// $user = 'sa';
		// $password = 'AbC123*-';
		// $host = '192.168.1.101';
		// $dbname = 'posmercadoweb';
		
		// Server 1and1
		//$user = 'iposplus2';
	//	$password = 'iN5eo&21';
	//	$host = 'iposplus.io';
//$dbname = 'db_iposplus';
		
		// Server Amazon
		$user = 'sa';
		$password = 'AbC123*-';
		$host = 'iposplus-test.cvnzfmrfty7q.us-east-2.rds.amazonaws.com';
		$dbname = 'db_iposplus';
		if (isset($_GET["APIKEY"]) || isset($_POST["APIKEY"])) {
		    $apikey = "";
		    if (isset($_GET["APIKEY"])) {
		        $apikey = $_GET["APIKEY"];
		    }
		    else if (isset($_POST["APIKEY"])) {
		        $apikey = $_POST["APIKEY"];
		    }
		    if ($apikey == "") {
		        return $conexion = new PDO("mysql:host=$host;dbname=$dbname;", $user, $password);
		    }
		    else {
    		    $dbname = 'iposplus_' . $apikey;
    		    error_log("Database " . $dbname);
    		    return $conexion = new PDO("mysql:host=$host;dbname=$dbname;", $user, $password);
		    }
		}
		else {
		    return $conexion = new PDO("mysql:host=$host;dbname=$dbname;", $user, $password);
		}
	}
}
?>
