PHP code example of bootpress / sqlite

1. Go to this page and download the library: Download bootpress/sqlite 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/ */

    

bootpress / sqlite example snippets

 php


use BootPress\SQLite\Component as Sqlite;

$db = new Sqlite; // An in-memory database

if ($db->created) {

    $db->settings('version', '1.0');
    
    $db->create('employees', array(
        'id' => 'INTEGER PRIMARY KEY',
        'name' => 'TEXT COLLATE NOCASE',
        'position' => 'TEXT NOT NULL DEFAULT ""',
    ), array('unique'=>'position'));
    
    // Wait, I just changed my mind:
    $db->create('employees', array(
        'id' => 'INTEGER PRIMARY KEY',
        'name' => 'TEXT UNIQUE COLLATE NOCASE',
        'title' => 'TEXT DEFAULT ""',
    ), 'title', array(
        'position' => 'title',
    ));
    
    $db->fts->create('results', 'search');
    
    // You can insert, update, and query an FTS table the same as any other.
    if ($stmt = $db->insert('results', array('docid', 'search'))) {
        $db->insert($stmt, array(100, 'Fisherman never die, they just get reel tired.'));
        $db->insert($stmt, array(101, 'If wishes were fishes, we\'d have a fish fry.'));
        $db->insert($stmt, array(102, 'Women want me, fish fear me.'));
        $db->insert($stmt, array(103, 'Good things come to those who bait.'));
        $db->insert($stmt, array(104, 'A reel expert can tackle anything.'));
    }
    
}

echo $db->settings('version'); // 1.0

echo $db->fts->count('results', 'fish')); // 2

print_r($db->fts->search('results', 'fish'));
/*
array(
    array(
        'docid' => 101,
        'snippet' => "If wishes were <b>fishes</b>, we'd have a <b>fish</b> fry.",
        'offsets' => '0 0 15 6 0 0 35 4',
        'rank' => 1.333,
    ),
    array(
        'docid' => 102,
        'snippet' => 'Women want me, <b>fish</b> fear me.',
        'offsets' => '0 0 15 4',
        'rank' => .666,
    ),
)
*/

echo implode(', ', $db->fts->words('results', 'fish', 101)); // fishes, fish