Example #1
0
<?php

ini_set('default_charset', 'UTF-8');
$jr = new JsonResponse('127.0.0.1', '', '', '');
$jr->init();
class JsonResponse
{
    public function __construct($hostname, $username, $password, $db)
    {
        try {
            $this->dbh = new PDO("mysql:host={$hostname};dbname={$db}", $username, $password, array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));
        } catch (PDOException $e) {
            print 'Exception : ' . $e->getMessage();
        }
    }
    public function init()
    {
        $this->openJSON();
        $qry = null;
        if (isset($_REQUEST['qry'])) {
            $qry = filter_var($_REQUEST['qry'], FILTER_SANITIZE_STRING);
            if (!$qry || $qry == "") {
                $qry = "";
            } else {
                $qry = "+(" . $qry . ")";
            }
        }
        $lmt = 10;
        if (isset($_REQUEST['lmt'])) {
            $lmt = (int) $_REQUEST['lmt'];
        }