<?php require_once 'PackagingDatabase.php'; ini_set('display_errors', true); error_reporting(E_ALL); // read configuration file $packagingServiceConfig = array(); // Retrieve values from configuration file require_once 'sys/ConfigArray.php'; $configArray = readConfig(); // connect to database $db = PackagingDatabase::connect($configArray['Database']['host'], $configArray['Database']['username'], $configArray['Database']['password'], $configArray['Database']['database']); // make sure we got a good db connection if ($db === false) { die('Unable to connect to database.'); } $method = isset($_REQUEST['method']) ? $_REQUEST['method'] : 'index'; switch ($method) { case 'GetFileProtectionStatus': echo json_encode(GetFileProtectionStatus($db)); break; case 'RequestFileProtection': echo json_encode(RequestFileProtection($db)); break; default: die('Invalid method.'); } function GetFileProtectionStatus($db) { if (!isset($_REQUEST['distributorId'])) { return array('success' => false, 'error' => 'You must provide the distributorId to return information for');
public static function connect($server, $username, $password, $database) { if (!self::$singleton) { $instance = new PackagingDatabase($server, $username, $password, $database); if (!$instance->_db) { return false; } self::$singleton = $instance; } return self::$singleton; }