PHP code example of r4ndsen / sqlite-php

1. Go to this page and download the library: Download r4ndsen/sqlite-php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

r4ndsen / sqlite-php example snippets




use r4ndsen\SQLite;
use r4ndsen\SQLite\Column;

$sqlite = new SQLite(':memory:');

$tasks = $sqlite->getTable('tasks');
$tasks
    ->addCreateColumn(Column::createIntegerColumn('id'))
    ->addCreateColumn(Column::createTextColumn('title')->disallowNull())
    ->addCreateColumn(Column::createIntegerColumn('is_done', 0))
    ->createIfNotExists();

$tasks->getDynamicInsertTable()
    ->push(['id' => 1, 'title' => 'Write docs'])
    ->push(['id' => 2, 'title' => 'Tag release', 'is_done' => 1])
    ->commit();

$openTasks = $sqlite->fetchPairs(
    'select id, title from tasks where is_done = :is_done order by id',
    ['is_done' => 0],
);
// [1 => 'Write docs']

foreach ($tasks as $row) {
    // Table implements IteratorAggregate, so you can iterate rows directly
}

$sqlite->validate(); // Runs PRAGMA integrity_check and throws on corruption
bash
composer 
bash
git clone https://github.com/r4ndsen/sqlite-php.git
cd sqlite-php
composer install