1. Go to this page and download the library: Download ufee/sqlite3 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/ */
if (!$table->exists()) {
// с указанием типов данных
$table->create([
'id' => 'INTEGER PRIMARY KEY',
'amount' => 'REAL',
'data1' => 'TEXT',
'data2' => 'BLOB',
'other' => 'INTEGER DEFAULT 5'
]);
// или без привязки к типу данных
$table->create([
'id,
'data',
'other'
]);
}
$select->where('id != another OR ...')
$select->having('other > another AND ...')
$count = $goods->select()->count();
// SELECT COUNT(*) as rows_count FROM goods LIMIT 1
$select = $goods->select()
->where('id', 1, '>')
->orderBy('hot');
$count = $select->count();
// SELECT COUNT(*) as rows_count FROM goods WHERE id > ... ORDER BY hot DESC LIMIT 1
$rows = $select->rows(3);
// SELECT * FROM goods WHERE id > ... ORDER BY hot DESC LIMIT 3
$select = $goods->select('id, category, title')
->where('hot', null, 'IS NOT')
->orderBy('hot');
$rows = $select->rows(2,2);
// SELECT id,category,title FROM goods WHERE hot IS NOT NULL ORDER BY hot DESC LIMIT 2 OFFSET 2
$select = $goods->select()->where('id', 1);
$row = $select->row();
// SELECT * FROM goods WHERE id = ... LIMIT 1
$select = $goods->select('title')->where('id', 1);
$title = $select->row('title');
// SELECT * FROM goods WHERE id = ... LIMIT 1
$select = $goods->select('g.id, g.category, g.title, m.descr, m.sale, g.hot, m.star, g.created_at')
->short('g')->innerJoin('goods_meta AS m', 'm.good_id=g.id')
->where('g.category', [1,2,3,4,5], 'IN')
->where('m.star', 1, '>')
->orderBy('m.star');
$count = $select->count();
// SELECT COUNT(*) as rows_count FROM goods AS g INNER JOIN goods_meta AS m ON m.good_id=g.id WHERE g.category IN (...,...,...,...,...) AND m.star > ... ORDER BY m.star DESC LIMIT 1
$rows = $select->rows();
// SELECT g.id,g.category,g.title,m.descr,m.sale,g.hot,m.star,g.created_at FROM goods AS g INNER JOIN goods_meta AS m ON m.good_id=g.id WHERE g.category IN (...,...,...,...,...) AND m.star > ... ORDER BY m.star DESC
$update = $goods->update('price, title, hot')
->where('id', 1)
->set([6950.10, 'Notebook Pro (hot)', 1]);
$update->row();
// UPDATE goods SET price=..., title = ..., hot = ... WHERE id = ... LIMIT 1
$update = $goods->update('hot')
->where('category', 3)
->orWhere('price', 5000, '<')
->set(1);
$update->rows();
// UPDATE goods SET hot = ... WHERE category = ... OR price < ...
$update->rows(3,2);
// UPDATE goods SET hot = ... WHERE category = ... OR price < ... LIMIT 3 OFFSET 2
$result = $goods->delete()->where('id', 5)->row();
// DELETE FROM goods WHERE id = ... LIMIT 1
$delete = $goods->delete()
->where('category', 4)
->orderBy('id');
$result = $delete->row();
// DELETE FROM goods WHERE category = ... ORDER BY id DESC LIMIT 1
$delete = $goods->delete()
->where('category', 4)
->orderBy('id');
$delete->rows(3);
// DELETE FROM goods WHERE category = ... ORDER BY id DESC LIMIT 3
$delete->rows(3, 3);
// DELETE FROM goods WHERE category = ... ORDER BY id DESC LIMIT 3 OFFSET 3
$delete->rows(3, 6);
// DELETE FROM goods WHERE category = ... ORDER BY id DESC LIMIT 3 OFFSET 6