Example #1
0
<?php

use Particle\Validator\Validator;
require_once '../vendor/autoload.php';
$file = "../storage/database.db";
if (is_writable('../storage/database.local.db')) {
    $file = '../storage/database.local.db';
}
$database = new medoo(['database_type' => 'sqlite', 'database_file' => $file]);
$comment = new SitePoint\Comment($database);
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $v = new Validator();
    $v->required('name')->lengthBetween(1, 100)->alnum(true);
    $v->required('email')->email()->lengthbetween(5, 255);
    $v->required('comment')->lengthBetween(10, null);
    $result = $v->validate($_POST);
    if ($result->isValid()) {
        try {
            $comment->setName($_POST['name'])->setEmail($_POST['email'])->setComment($_POST['comment'])->save();
            header('Location: /');
            return;
        } catch (\Exception $e) {
            die($e->getMessage());
        }
    } else {
        dump($result->getMessages());
    }
}
//   dump($database);
?>
<!doctype html>
Example #2
0
<?php

require_once '../vendor/autoload.php';
echo "Hello World";
$file = '../storage/database.db';
if (is_writable('../storage/database.local.db')) {
    $file = '../storage/database.local.db';
}
$database = new medoo(['database_type' => 'sqlite', 'database_file' => '../storage/database.db']);
$comment = new SitePoint\Comment($database);
$comment->setEmail('*****@*****.**')->setName('Bruno Skvorc')->setComment('It works!')->setComment('Hooray! Saving comments works!')->save();
dump($database->error());
?>

<!doctype html>
<html class="no-js" lang="">
    <head>
        <meta charset="utf-8">
        <meta http-equiv="x-ua-compatible" content="ie=edge">
        <title></title>
        <meta name="description" content="">
        <meta name="viewport" content="width=device-width, initial-scale=1">

        <link rel="apple-touch-icon" href="apple-touch-icon.png">
        <!-- Place favicon.ico in the root directory -->

        <link rel="stylesheet" href="css/normalize.css">
        <link rel="stylesheet" href="css/main.css">
        <script src="js/vendor/modernizr-2.8.3.min.js"></script>
    </head>
    <body>