- file_get_contents: documentation ( source)
- json_decode: documentation ( source)
<?php
//set up the database connection
$servername = "192.129.1.209";
$username = "meaadmin";
$password = "Kasten_15&";
$dbname = "typo3mea";
$dataurl = "http://127.0.0.1:8000/api/thesis?format=json";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
//read the json file content
$jsondata = file_get_contents($dataurl);
//convert json object to php array
$data = json_decode($jsondata, true);
echo file_get_contents($dataurl);
if (empty($data)) {
echo "empty";
}
$b = count($data);
echo $b;
//insert into mysql table
foreach($data->objects as $obj) {
$sql = "INSERT INTO mea_thesis(title) VALUES('".$obj->title."')";
if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
}
echo "test";
$conn->close();
echo file_get_contents("http://google.com");
//echo phpinfo();
?>