PHP Boilerplate for storing Text/Timestamp entries in a SQLite Database.
I needed a dead-simple solution for storing status updates without any additional setup. Also, my website resides on a shared hosting plan where only PHP is available.
The solutions i found where either too static or too bloated to my liking, so i came up with my own. But beware: As of now i guess this Project only qualifies as a collection of code snippets or a boilerplate at best.
If you are looking for a more refined microblogging solution, take a look at oelna/microblog.
- Copy
nanoblog.php
to your webspace. - Include with
<?php include('nanoblog.php') ?>
and directly use the php functions - or use the HTTP API. However, only insertion and deletion are available.
- Use
db_insert
function - or do a HTTP POST Request and include add and secret parameters, eg.
add=<newconent>&secret=<mysecret>
- Remove latest entry with
db_delete_latest
function - or do a HTTP POST Request and include delete and secret parameters, eg.
delete&secret=<mysecret>
I included nanoblog.php
into my index.php
and did the following to display a list of Posts:
<?php
$posts = db_select_posts();
if ($posts) {
foreach ($posts as $item) {
$datetime = strftime('%a., %d.%m.%Y - %H:%M', $item['post_timestamp']);
$post = $item["post_content"]; ?>
<article class="post">
<b class="date"><?= $datetime ?></b><br>
<?= $post ?>
</article>
<?php
}
}
Insertion and removal is done through a JavaScript-Client which hits the HTTP Endpoints with XMLHttpRequest