sqlitecloud / sqlitecloud-php

PHP drivers for SQLiteCloud
https://sqlitecloud.io
3 stars 0 forks source link
cloud database sqlite

Driver for SQLite Cloud

SQLite Cloud logo

Test and QA codecov Packagist Version PHP


SQLite Cloud is a powerful PHP package that allows you to interact with the SQLite Cloud database seamlessly. It provides methods for various database operations. This package is designed to simplify database operations in PHP applications, making it easier than ever to work with SQLite Cloud.

Example

$ composer require sqlitecloud/sqlitecloud
<?php

require_once 'vendor/autoload.php';

use SQLiteCloud\SQLiteCloudClient;
use SQLiteCloud\SQLiteCloudRowset;

// Open the connection to SQLite Cloud
$sqlite = new SQLiteCloudClient();
$sqlite->connectWithString('sqlitecloud://myhost.sqlite.cloud:8860?apikey=myapikey');

// You can autoselect the database during the connect call
// by adding the database name as path of the SQLite Cloud
// connection string, eg:
// $sqlite->connectWithString("sqlitecloud://myhost.sqlite.cloud:8860/mydatabase?apikey=myapikey");
$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();