querySingle("SELECT TRUE FROM pragma_table_info('links')"); if (!$exists) { $db->exec(<<url; $audio = $data->audio; $video = $data->video; if ($url !== null && $audio !== null && $video !== null) { $stmt = $db->prepare('INSERT INTO links (url, audio, video) VALUES (:url, :audio, :video);'); $stmt->bindValue(':url', $url); $stmt->bindValue(':audio', $audio); $stmt->bindValue(':video', $video); $result = $stmt->execute(); if (!$result) { http_response_code(500); die(); } $result = $db->querySingle("SELECT last_insert_rowid()"); print_r($result); } else { http_response_code(400); die(); } } else { $result = []; $db_result = $db->query("SELECT * FROM links;"); while ($row = $db_result->fetchArray(SQLITE3_ASSOC)) { $row["audio"] = $row["audio"] == 1; $row["video"] = $row["video"] == 1; array_push($result, $row); } header('Content-type: application/json; charset=utf-8'); echo json_encode($result); }