Quick Start Guide for PHP

This guide will help you get up and running with Backendless quickly so you can start using Backendless services and APIs from PHP applications. By the end of the guide you will have a configured working environment and a basic project with the code communicating with the Backendless services.

  1. Login to your Backendless account or register to create a new one.
  2. Download the Backendless for PHP SDK from the Backendless SDK Downloads page.
  3. Create a new PHP application project or open an existing project.
  4. Unzip the downloaded SDK into a directory in your project structure. Alternatively you can create a new directory. For example, we created directory vendor  and unzipped the SDK archive into it. As result, you get the following directory structure:
  5. Notice autoload.php  located in the root of the /vendor/backendless  directory. It is important to include that file in the main script of your project. To do this create index.php  in the root of project and add following code:

  6. Get your Backendless application and API keys for PHP SDK from the Backendless Console. The keys can be found at the Manage > App Settings section. For the PHP applications, you need to get the REST Secret Key as shown below:
  7. Add Backendless application initialization code block to index.php file to set the application ID, REST Secret Key and application version:

  8. The next step is to add a Backendless API call to register a new application user. Consider the following code (still adding it to index.php):
  9. Run your PHP application ( use a web server or cli ). A new Backendless user is registered with Backendless. You can verify the registered user in the Data section of the Backendless Console (the Users table is selected by default):
  10. The next step in exploring the Backendless API is creating and saving a PHP object in the Backendless persistent storage. Backendless API works with PHP objects for the classes you declare in your application. To see the API in action, create a PHP class called Comment  which will be saved in Comment.php  located in the root of the project:

  11. The following code (located in index.php) creates an instance of the “Comment” class and stores it in the Backendless data storage (highlighted lines have been added to the code you already had in index.php):

  12. If you already ran the code to register the user, and run the example above again, the backend will report the following error:

    To avoid getting the error, you can either change the email address of the registering user or delete the user account in Backendless console.
  13. Once you run the code, you can verify that the “Comment” data table has been created with the columns corresponding to the properties of the Comment class and it contains the saved object: