I have use following to add object to Firebase database.
$url = "https://myfb.firebaseio.com/api/types/ty/packs.json";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $userData);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded'));
$jsonResponse = curl_exec($ch);
if(curl_errno($ch))
{
echo 'Curl error: ' . curl_error($ch);
}
curl_close($ch);
The $userData
will be kept under uniquely generated node in our database as follows.
I want to give my custom key to that node. How I do this?
If you are using Firebase REST API to insert data in Firebase using your custom Id and without any child(auto-generated) id, use 'Put' Instead of 'Post'.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With