PHP SDK Getting Started

This powerful package provides methods that simplify performing database operations in PHP applications, making it easier than ever to work with SQLite in the cloud. We encourage all users to log encountered issues in the SDK’s issues backlog.

Install

  • Run the following command to initialize a PHP project and install the SDK.
$ composer require sqlitecloud/sqlitecloud

Configure your database connection

  • In your SQLite Cloud account dashboard, click on Show connection strings, copy the Connection String, and replace <your-connection-string> below.
$sqlite->connectWithString("<your-connection-string>");
  • You can modify the connection string to include the name of the database to query.
    • Here, the provided port (8860) and database (chinook.sqlite) will query the sample dataset that comes pre-loaded with SQLite Cloud. Replace to query your own datasets.
$sqlite->connectWithString('sqlitecloud://{hostname}:8860/chinook.sqlite?apikey={apikey}');

Connect and query

  • Include the following snippet in a new example.php file.
  • NOTE: $sqlite->execute("USE DATABASE {$db_name}"); is only necessary if your connection string does NOT specify the name of the database to query.
<?php

require_once 'vendor/autoload.php';

use SQLiteCloud\SQLiteCloudClient;
use SQLiteCloud\SQLiteCloudRowset;

$sqlite = new SQLiteCloudClient();
$sqlite->connectWithString("<your-connection-string>");

$db_name = 'chinook.sqlite';
$sqlite->execute("USE DATABASE {$db_name}");

/** @var SQLiteCloudRowset */
$rowset = $sqlite->execute('SELECT * FROM albums WHERE ArtistId = 2');

printf('%d rows' . PHP_EOL, $rowset->nrows);
printf('%s | %s | %s' . PHP_EOL, $rowset->name(0), $rowset->name(1), $rowset->name(2));
for ($i = 0; $i < $rowset->nrows; $i++) {
  printf('%s | %s | %s' . PHP_EOL, $rowset->value($i, 0), $rowset->value($i, 1), $rowset->value($i, 2));
}

$sqlite->disconnect();
  • Run your app!
php example.php

PHP Admin Dashboard

You can use SQLite Cloud’s simplified PHP Admin interface to administer any node.

  • Clone the PHP SDK, install lock file dependencies, and run the dashboard locally.
git clone https://github.com/sqlitecloud/sqlitecloud-php.git

composer update # or composer install
cd admin
php -S localhost:8000
  • Login as your admin user.
    • In your SQLite Cloud account dashboard, click on Show connection strings, copy the Deployment string, and paste in Hostname.
    • In your dashboard left nav, select Settings, then Users. Copy your admin user’s username and paste in Username.
    • In your User’s row, click the down chevron, then Edit. Enter a Password and Save. Paste in Password.

PHP Admin Login

PHP Admin Overview