This commit is contained in:
2023-04-12 14:22:57 +08:00
parent bdace88adc
commit f69e9ad87d
+18 -17
View File
@@ -297,10 +297,12 @@ function init()
if (str_starts_with($_SERVER['REQUEST_URI'], "/file")) {
$id = explode("/", $_SERVER['REQUEST_URI'])[2] ?? "";
$results = query_db("SELECT * FROM files WHERE uuid='{$id}' LIMIT 1");
$row = $results->fetchArray();
$stmt = get_db()->prepare("SELECT * FROM files WHERE uuid=:uuid LIMIT 1");
$stmt->bindParam(':uuid', $id);
if(empty($row['stc'])){
$row = $stmt->fetch();
if (empty($row['stc'])) {
echo_json([
"code" => 1,
"msg" => "图片不存在",
@@ -333,23 +335,22 @@ function show_page()
}
}
function exec_db($sql){
$db = new SQLite3(DATA_PATH . 'data.db');
// 创建表
function get_db()
{
$db = new PDO('sqlite:' . DATA_PATH . 'data.db');
return $db;
}
function exec_db($sql)
{
$db = get_db();
$db->exec($sql);
$db->close();
}
function query_db($sql){
$db = new SQLite3(DATA_PATH . 'data.db');
// 创建表
$results = $db->query($sql);
$db->close();
return $results;
}
function inti_db(){
function inti_db()
{
exec_db('CREATE TABLE IF NOT EXISTS files (id INTEGER PRIMARY KEY, uuid TEXT, src TEXT)');
}