Home > OS >  Getting error on set data in firebase realtime database...Call to a member function getReference() o
Getting error on set data in firebase realtime database...Call to a member function getReference() o

Time:01-04

Hi I'm integrating firebase PHP SDK in my codeigniter project and when I call my api then it's through error message :Call to a member function getReference() on null

My code is:

<?php

use Kreait\Firebase\Factory;

$factory = (new Factory)->withServiceAccount(APPPATH.'config/globaltaxi-277114-firebase-adminsdk-5s93b-2a0246ed22.json');

$database = $factory->createDatabase();

//$firebase->set($uri, $);
$ci = &get_instance();



function AddDriverToFirbase($uri, $driver_string)
{
     
    $ci = &get_instance();
     

    $firebaseDBComUrl = $ci->config->item('firebase_url');
    $fireBaseNewRoomStorePath = $firebaseDBComUrl; //.$uri;
 

    $database->getReference($fireBaseNewRoomStorePath)->getChild($uri)->set($driver_string);
}

and error response is An uncaught Exception was encountered Type: Error

Message: Call to a member function getReference() on null

anyone can you please help me for fix this issue. Thanks.

CodePudding user response:

First I was check my php version and update sdk according version after that resolve all lib related issues.

There are issue found regarding uri and I need to update like below:

$database->getReference($uri)->set($driver_string);

Means no need for all url, just need to add node name which one we need to use for add our data.

  •  Tags:  
  • Related