Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Failed to connect my Firebase DB with PHP SDK

I am using ktamas77/firebase-php at github to connect my Firebase data.

My code below. Replaced of confidential info with ******.

<html>
<head>
<title>My web</title>
</head>
<body>

    <?php
         require_once 'firebase/firebaseLib.php';
         require_once 'firebase/firebaseStub.php';
         require_once 'firebase/firebaseInterface.php';

         echo "1";

         const DEFAULT_URL = 'https://********.firebaseio.com/';
         const DEFAULT_TOKEN = '***************************************';
         const DEFAULT_PATH = '/firebase/example';

         echo "2";

         $firebase = new Firebase(DEFAULT_URL, DEFAULT_TOKEN); 

         echo "3";

    ?>

</body>
</html>

I also tried:

$firebase = new \Firebase\FirebaseLib(DEFAULT_URL, DEFAULT_TOKEN);

Output is: 1 2. It seems it fails while it is trying to create the new Firebase.

What am I doing wrong? Thanks!

like image 714
adi319 Avatar asked Feb 23 '17 18:02

adi319


People also ask

Can you connect Firebase to PHP?

Q: Can I use Firebase with PHP? A: Yes, Firebase provides a comprehensive API for integrating the platform with your PHP projects.

What is Firebase SDK?

The Firebase Admin Java SDK enables access to Firebase services from privileged environments (such as servers or cloud) in Java. Currently this SDK provides Firebase custom authentication support, and Firebase realtime database access. For more information, visit the Firebase Admin SDK setup guide.


1 Answers

Are you sure your library is loaded properly? Pls add directory/file structure.

You can test loaded library with

class_exists ('Firebase')

or

file_exists ( 'firebase/firebaseLib.php' );
like image 163
Cibula Avatar answered Sep 27 '22 18:09

Cibula