PHP code example of tenglin / sqlite3-database-class
1. Go to this page and download the library: Download tenglin/sqlite3-database-class 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/ */
tenglin / sqlite3-database-class example snippets
$db = new SQLite3DB('./data.db', 'ejcms_');
// 或是
$db = new SQLite3DB();
$db->dbfile = './data.db';
$db->prefix = 'ejcms_';
$db->update('user', [
'name' => 'database'
], ['id' => '1']);
// UPDATE ejcms_user SET [name] = 'database' WHERE id = '1';
// 或是
$db->where('id', [1, 2, 3], 'in');
$db->update('user', [
'name' => 'database'
]);
// UPDATE ejcms_user SET [name] = 'database' WHERE id in ('1', '2', '3');
$db->delete('user', ['id' => '1']);
// DELETE FROM [ejcms_user] WHERE id = '1';
// 或是
$db->where('id', [1, 2, 3], 'in');
$db->delete('user');
// DELETE FROM [ejcms_user] WHERE id in ('1', '2', '3');
$result = $db->detail('user', ['id' => '1']);
// SELECT * FROM [ejcms_user] WHERE id = '1' LIMIT 1;
print_r($result);
// 或是
$db->join('user1 b', 'a.id = b.id', 'left');
$result = $db->detail('user a', ['a.id' => '1']);
// SELECT * FROM [ejcms_user a] left JOIN user1 b ON a.id = b.id WHERE a.id = '1' LIMIT 1;
print_r($result);
// 或是
$tables = [];
$tables['table'] = 'user a';
$tables['join'] = ['table' => 'user1 b', 'condition' => 'a.id = b.id', 'type' => 'left'];
$result = $db->detail($tables, ['a.id' => '1']);
// SELECT * FROM [ejcms_user a] left JOIN user1 b ON a.id = b.id WHERE a.id = '1' LIMIT 1;
print_r($result);
$db->where('cid', 1);
$result = $db->items('user');
// SELECT * FROM [ejcms_user] WHERE cid = '1';
print_r($result);
$tables = [];
$tables['table'] = 'user a';
$tables['join'] = ['table' => 'user1 b', 'condition' => 'a.id = b.id', 'type' => 'left'];
$db->where('a.cid', 1);
$db->where('a.name', 'sql%', 'like');
$db->orwhere('a.name', 'data');
$db->orderby('a.id', 'desc');
$result = $db->items($tables);
// SELECT * FROM [ejcms_user a] left JOIN user1 b ON a.id = b.id WHERE a.cid = '1' AND a.name like 'sql%' OR a.name = 'data' ORDER BY a.id DESC;
print_r($result);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.