<?php require_once 'vendor/autoload.php'; use leoshtika\libs\Pagination; use leoshtika\libs\Sqlite; use leoshtika\libs\UserFaker; $sqliteFile = 'demo.sqlite'; // Create a new sqlite db if not exists and load some dummy data. // After the database is created, you don't need this line of code anymore UserFaker::create($sqliteFile, 120); $dbh = Sqlite::connect($sqliteFile); // Get the total number of records $totalRecords = $dbh->query('SELECT count(*) FROM user')->fetch(PDO::FETCH_COLUMN); // Instantiate the Pagination $pagination = new Pagination($_GET['page'], $totalRecords, 10); // Get records using the pagination $sth = $dbh->prepare('SELECT * FROM user LIMIT :offset, :records'); $sth->bindValue(':offset', $pagination->offset(), PDO::PARAM_INT); $sth->bindValue(':records', $pagination->getRecordsPerPage(), PDO::PARAM_INT); $sth->execute(); $users = $sth->fetchAll(PDO::FETCH_OBJ); ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Pagination</title> <!-- Bootstrap --> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css"> </head> <body class="container-fluid">
<?php /** * Demo SQLite * * @author Leonard Shtika <*****@*****.**> * @link http://leonard.shtika.info * @copyright (C) Leonard Shtika * @license MIT. See the file LICENSE for copying permission. */ require_once 'vendor/autoload.php'; use leoshtika\libs\Sqlite; use leoshtika\libs\UserFaker; $sqliteFile = 'demo.sqlite'; // Create the database if not exists UserFaker::create($sqliteFile); $dbh = Sqlite::connect($sqliteFile); $sth = $dbh->prepare('SELECT * FROM user'); $sth->execute(); $users = $sth->fetchAll(PDO::FETCH_ASSOC); foreach ($users as $user) { echo $user['name'] . ' Email: ' . $user['email']; echo '<hr>'; }