|
| 1 | +# Attogram Database |
| 2 | + |
| 3 | +SQLite database access for PHP 7. Small, one class, and highly opinionated. |
| 4 | + |
| 5 | +* Repository: **<https://github.com/attogram/database>** |
| 6 | + |
| 7 | +[](https://codeclimate.com/github/attogram/database/maintainability) |
| 8 | +[](https://travis-ci.org/attogram/database) |
| 9 | +[](https://packagist.org/packages/attogram/database) |
| 10 | + |
| 11 | +## Install |
| 12 | + |
| 13 | +``` |
| 14 | +composer require attogram/database |
| 15 | +``` |
| 16 | + |
| 17 | +## Examples |
| 18 | + |
| 19 | +one table: |
| 20 | + |
| 21 | +```php |
| 22 | +declare(strict_types = 1); |
| 23 | + |
| 24 | +use Attogram\Database\Database; |
| 25 | + |
| 26 | +require '../vendor/autoload.php'; |
| 27 | + |
| 28 | +$database = new Database(); |
| 29 | +$database->setDatabaseFile('./test.one.sqlite'); |
| 30 | +$database->setCreateTables("CREATE TABLE 'one' ('foo' TEXT)"); |
| 31 | + |
| 32 | +try { |
| 33 | + $database->raw("INSERT INTO one ('foo') VALUES (CURRENT_TIMESTAMP)"); |
| 34 | + $arrayResults = $database->query("SELECT * FROM 'one'"); |
| 35 | + print_r($arrayResults); |
| 36 | +} catch (Throwable $error) { |
| 37 | + print 'ERROR: ' . $error->getMessage(); |
| 38 | +} |
| 39 | +``` |
| 40 | + |
| 41 | +two tables: |
| 42 | + |
| 43 | +```php |
| 44 | +declare(strict_types = 1); |
| 45 | + |
| 46 | +use Attogram\Database\Database; |
| 47 | + |
| 48 | +require '../vendor/autoload.php'; |
| 49 | + |
| 50 | +$database = new Database(); |
| 51 | +$database->setDatabaseFile('./test.two.sqlite'); |
| 52 | + |
| 53 | +$tables = [ |
| 54 | + "CREATE TABLE 'one' ('foo' TEXT)", |
| 55 | + "CREATE TABLE 'two' ('bar' TEXT)", |
| 56 | +]; |
| 57 | +$database->setCreateTables($tables); |
| 58 | + |
| 59 | +try { |
| 60 | + $database->raw("INSERT INTO one ('foo') VALUES (CURRENT_TIMESTAMP)"); |
| 61 | + $database->raw("INSERT INTO two ('bar') VALUES (CURRENT_TIMESTAMP)"); |
| 62 | + $arrayResults = $database->query("SELECT * FROM 'one'"); |
| 63 | + print_r($arrayResults); |
| 64 | + $arrayResults = $database->query("SELECT * FROM 'two'"); |
| 65 | + print_r($arrayResults); |
| 66 | +} catch (Throwable $error) { |
| 67 | + print 'ERROR: ' . $error->getMessage(); |
| 68 | +} |
| 69 | +``` |
0 commit comments