Reputation: 245
I need to store each individual value from the JSON API response as a variable so I can then store them in MySQL.
I am able to access the top level data shown here when echoing id, but cannot seem to access the nested data such as name>text.
I am new to API usage so any help is appreciated.
<?php
include("restclient.php");
$api = new RestClient(array(
'base_url' => "https://www.eventbriteapi.com/v3",
));
$result = $api->get("/events/" . $_POST['id_eventbrite'] . "/?token=MYTOKENISHERE");
echo $result['id'];
?>
Upvotes: 1
Views: 1337
Reputation: 264
First you need to create a table with the corresponding columns of your Json result. Then you simply generate a query and place the values in place. For example, lets say your Json result is like this
You'll need to create the corresponding table
CREATE TABLE person ( id int, name varchar(25), age int);
The query would be something like this:
INSERT INTO person (id, name, age) VALUES(?,?,?);
To bind the data, you'll do something like this:
$stmt = $mysqli->prepare("INSERT INTO person (id, name, age) VALUES(?,?,?)");
$stmt->bind_param($response['id'], $response['name'], $response['age']);
Then you execute the query and done.
For detailed information about parameter binding, check the php documentation
http://php.net/manual/en/mysqli-stmt.bind-param.php
Upvotes: 0
Reputation: 1729
Api result or json or xml, you should parse it. if json use var_dump(json_decode($result, true));
if xml use json_decode(json_encode(simplexml_load_string($result)),true);
Upvotes: 2