Exemplo n.º 1
0
<?php

header('Access-Control-Allow-Origin: *');
//http://stackoverflow.com/questions/20035101/no-access-control-allow-origin-header-is-present-on-the-requested-resource
header('Access-Control-Allow-Methods: GET, POST, OPTIONS');
//http://stackoverflow.com/questions/13400594/understanding-xmlhttprequest-over-cors-responsetext?lq=1
require_once 'Jengine.php';
$template = Jengine::json_template('http://localhost/AngularSearch/data1.json');
$json_data2 = array("David", "Cows", "grey", "http://www.gettyimages.com/gi-resources/images/CreativeImages/Hero-527920799.jpg");
for ($x = 0; $x <= 1000; $x++) {
    $template = Jengine::json_add($template, $json_data2);
}
echo $template;
Exemplo n.º 2
0
            // output data of each row
            $jsonstring = $braceopen;
            while ($row = $result->fetch_assoc()) {
                $jsonstring = $jsonstring . json_encode($row) . ",";
            }
            $jsonstring = trim($jsonstring, ",") . $braceclose;
            return $jsonstring;
            //print_r(json_decode($jsonstring));
        } else {
            return "</br><hr><span style='color: red'>Error in generating Json:</span> please ensure that the below parameter passed to Jengine is a mysqli_result object </br><hr></br><div style='color: red'>Parameter:</div></div></br> " . $result . "</br><hr></br></br>";
        }
    }
}
$json_attributes = array("color", "speed", "type");
$json_data1 = array("red", "slow", "gold");
$json_data2 = array("Nickelia Lionjack", "Scarborough", "Trinidad");
$template = Jengine::json_template($json_attributes);
//or result returned by json_mysqli_result($result )
//$template =Jengine::json_template('http://localhost/PHP-JSONengine/test/test.json');
//echo $template;
//link to a json source
//json attributes, that would by default be used to create an empty json template
//the
$template = Jengine::json_add($template, $json_data2);
$template = Jengine::json_add($template, $json_data1);
//$check2=Jengine::json_mysqli_result($colors);
//echo $template;
$data_to_delete = array("color" => "red", "type" => "gold");
$template = Jengine::json_remove($template, $data_to_delete);
//echo $template;
//print_r(json_decode($template,true));
[{
    "Index1": "*value1",
	"Index3": "value2",
	"Index3": "value3"
}]
*/
require_once 'Jengine.php';
$servername = "";
//localhost
$username = "";
//root
$password = "";
$dbname = "";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT * FROM somedb ";
$result = $conn->query($sql);
echo "<b> Using template loaded from  data source</b>";
echo '</br></br>';
echo '</br></br>';
$template = Jengine::json_mysqli_result($result);
echo $template;
$conn->close();
?>

</body>
</html>
Exemplo n.º 4
0
$template = Jengine::json_template($json_attributes);
echo $template;
//Result:
/*
  [{
       "color": "*empty*",
       "speed": "*empty*",
       "type": "*empty*"
   }]
*/
echo '</br></br></br>';
echo "<b> Adding data to the new Template</b>";
echo '</br></br>';
$json_data1 = array("red", "slow", "volvo");
$json_data2 = array("Green", "fast", "viper");
$template = Jengine::json_add($template, $json_data1);
echo $template;
//Result:
//[{"color":"red","speed":"slow","type":"volvo"}]
echo '</br></br>';
$template = Jengine::json_add($template, $json_data2);
echo $template;
echo '</br></br></br>';
//Result:
//[{"color":"red","speed":"slow","type":"volvo"},{"color":"Green","speed":"fast","type":"viper"}]
echo "<b> Using template loaded from  data source</b>";
echo '</br></br>';
echo '</br></br>';
$template = Jengine::json_template('http://localhost/PHP-JSONengine/data.json');
echo $template;
//[{ "Name": "David Charles", "City": "Berlin", "Country": "Germany" }, { "Name": "Ana Trujillo Emparedados y helados", "City": "México D.F.", "Country": "Mexico" }, { "Name": "Antonio Moreno Taquería", "City": "México D.F.", "Country": "Mexico" }]
Exemplo n.º 5
0
<!DOCTYPE html>
<html>
<body>

<?php 
require_once 'Jengine.php';
$servername = "localhost";
$username = "******";
$password = "";
$dbname = "hotel_reservations";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT * FROM room";
$result = $conn->query($sql);
$check2 = Jengine::json_mysqli_result($result);
echo $check2;
var_dump($result);
// Aresult Object is returned
$conn->close();
?>

</body>
</html>