attogram/database

PHP access to SQLite databases.

Fund package maintenance!
attogram

Installs: 86

Dependents: 1

Suggesters: 0

Security: 0

Stars: 3

Watchers: 2

Forks: 0

Open Issues: 1

Type:project

v1.1.1 2019-05-27 09:30 UTC

This package is auto-updated.

Last update: 2024-12-16 08:13:27 UTC


README

SQLite database access for PHP 7. Small, one class, and highly opinionated.

Maintainability Build Status Latest Stable Version

Install

composer require attogram/database

Examples

one table:

declare(strict_types = 1);

use Attogram\Database\Database;

require '../vendor/autoload.php';

$database = new Database();
$database->setDatabaseFile('./test.one.sqlite');
$database->setCreateTables("CREATE TABLE 'one' ('foo' TEXT)");

try {
    $database->raw("INSERT INTO one ('foo') VALUES (CURRENT_TIMESTAMP)");
    $arrayResults = $database->query("SELECT * FROM 'one'");
    print_r($arrayResults);
} catch (Throwable $error) {
    print 'ERROR: ' . $error->getMessage();
}

two tables:

declare(strict_types = 1);

use Attogram\Database\Database;

require '../vendor/autoload.php';

$database = new Database();
$database->setDatabaseFile('./test.two.sqlite');

$tables = [
    "CREATE TABLE 'one' ('foo' TEXT)",
    "CREATE TABLE 'two' ('bar' TEXT)",
];
$database->setCreateTables($tables);

try {
    $database->raw("INSERT INTO one ('foo') VALUES (CURRENT_TIMESTAMP)");
    $database->raw("INSERT INTO two ('bar') VALUES (CURRENT_TIMESTAMP)");
    $arrayResults = $database->query("SELECT * FROM 'one'");
    print_r($arrayResults);
    $arrayResults = $database->query("SELECT * FROM 'two'");
    print_r($arrayResults);
} catch (Throwable $error) {
    print 'ERROR: ' . $error->getMessage();
}