Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/attogram/database

SQLite database access for PHP 7. Small, one class, and highly opinionated.
https://github.com/attogram/database

php-database-class php-database-connection php7 sqlite

Last synced: about 18 hours ago
JSON representation

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

Awesome Lists containing this project

README

        

# Attogram Database

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

[![Maintainability](https://api.codeclimate.com/v1/badges/473e68db98ac442429c1/maintainability)](https://codeclimate.com/github/attogram/database/maintainability)
[![Build Status](https://travis-ci.org/attogram/database.svg?branch=master)](https://travis-ci.org/attogram/database)
[![Latest Stable Version](https://poser.pugx.org/attogram/database/v/stable)](https://packagist.org/packages/attogram/database)

## Install

```
composer require attogram/database
```

## Examples

one table:

```php
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:

```php
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();
}
```