PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, March 12, 2022

[FIXED] Getting error on set data in firebase realtime database...Call to a member function getReference() on null?

 March 12, 2022     codeigniter, firebase, firebase-realtime-database, php     No comments   

Issue

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.


Solution

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.



Answered By - Neeraj Prajapati
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing