PHP code example of youloge / sqlite
1. Go to this page and download the library: Download youloge/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/ */
youloge / sqlite example snippets
composer
return [
'enable' => true,
// 绝对路径 需要 / 开头 结尾 不需要
'absolute'=>'C:/Users/Micateam/Desktop/youloge/composer/public',
// 相对路径 数据库配置`JSON`格式 + MD5后续加入 方式配置变动
'dump'=>'youloge.sqlite.json',
// 文件后缀 你改成mp4都没问题 Sqlite3 能识别
'format'=>'db'
];
php
use Youloge\Sqlite\Sqlite;
if(!function_exists('sqlite')){
function sqlite($dir,$file){
return new Sqlite($dir,$file);
}
}
// 任意地方 使用
$db = sqlite('文件目录/目录','文件名(不包含后缀)'); // 返回是一个`SQLite3 类`
$db::version(); // 返回版本/配置
var_export(get_class_methods($db)); // 打印全部方法
php
$db = sqlite('open.site','youloge');
sqlite::version(); // 静态调用
php
$insert = sqlite->insert('info',['state'=>'正常']);
echo $insert; // 返回插入的行数 行数 ≠ 自增ID
php
$insert = sqlite->insert('info',[['state'=>'正常'],['state'=>'正常'],['state'=>'正常']]);
echo $insert; // 返回插入的行数 行数 ≠ 自增ID
php
$update = sqlite->update('info',['state'=>'禁言'],['id'=>1]);
echo $update; // 返回1,0
php
$update = sqlite->update('info',['state'=>'禁言'],['id > 5','state'=>'正常']);
echo $update; // 返回1,0
php
$delete = sqlite->delete('info',['state'=>'禁言']); // 键值对
$delete = sqlite->delete('info',['state IS NULL']); // 纯数组
echo $delete; // 返回1,0
php
$row_array = sqlite->row_array('info','*',['id'=>100]);
$row_array = sqlite->row_array('info',['*','id as uuid'],['id < 100','state'=>'正常'],'created desc');
echo $row_array; // []
php
$result_array = sqlite->result_array('info','*',['id'=>100],10,0);
echo $result_array; // []
php
$count_array = sqlite->count_array('info','*',['id'=>100],10,0);
echo $count_array; // ['list'=>[],'count'=>0,'limit'=>10,'offset'=>0];