Ejemplo n.º 1
0
    {
        try {
            // get connession
            $conn = new PDO("mysql:host=" . $GLOBALS['$dbhost'] . ";dbname=" . $GLOBALS['$dbname'] . "", $GLOBALS['$dbuser'], $GLOBALS['$dbpass']);
            // set the PDO error mode to exception
            $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
            // select query
            $sql = "SELECT    country_code,\n                          GROUP_CONCAT(CONCAT( release_tag,'#',num )) AS installations,\n                          country_name\n\n                FROM      ( SELECT  country_code,\n                                    release_tag,\n                                    country_name,\n                                    reg_date,\n                                    COUNT(release_tag) AS num\n                            FROM phone_home_tb\n                            WHERE reg_date >= DATE_SUB(CURDATE(), INTERVAL 10 DAY)\n                            GROUP BY release_tag, country_code\n                          ) AS t\n\n                GROUP BY  country_code;";
            // prepare statement
            $stmt = $conn->prepare($sql);
            // execute query
            $stmt->execute();
            // create new empty array
            $infos = array();
            // set the resulting array to associative
            for ($i = 0; $row = $stmt->fetch(); $i++) {
                array_push($infos, array('installations' => $row['installations'], 'country_code' => $row['country_code'], 'country_name' => $row['country_name']));
            }
            // close connession
            $conn = null;
            // return info inserted
            return '{"nethservers":' . json_encode($infos) . '}';
        } catch (PDOException $e) {
            echo $e->getMessage();
        }
    }
}
$rest = new RestServer();
$rest->addServiceClass(AddInfo);
$rest->addServiceClass(GetInfo);
$rest->handle();
Ejemplo n.º 2
0
require_once "RestServer.php";
class Hello
{
    // example: http://path/to/examples/InstanceExample.php?method=sayHello&name=World
    public function sayHello($name)
    {
        return array("Response" => "Hello, " . $name);
    }
    // It doesn't matter if the methods are instance or static
    // example: http://path/to/examples/InstanceExample.php?method=addInts&n1=3&n2=5
    public static function addInts($n1, $n2)
    {
        if (is_numeric($n1) && is_numeric($n2)) {
            return array("Result" => "{$n1} + {$n2} = " . (string) ($n1 + $n2));
        } else {
            return array("Error" => "Parameters must be numeric.");
        }
    }
}
class Goodbye
{
    // example: http://path/to/examples/InstanceExample.php?method=sayGoodbye&name=World
    public function sayGoodbye($name)
    {
        return array("Response" => "Goodbye, " . $name);
    }
}
$rest = new RestServer();
$rest->addServiceClass(Hello);
$rest->addServiceClass(Goodbye);
$rest->handle();