Exemple #1
0
<?php

define('REQUEST_MICROTIME', microtime(1));

require 'env.php';

require 'inc.functions.php';

require '../inc/db/db_sqlite.php'; // https://github.com/rudiedirkx/db_generic
//$db = db_mysql::open(array('user' => 'usagerplus', 'pass' => 'usager', 'database' => 'tests'));
$db = db_sqlite::open(array('database' => 'db/series.sqlite3'));

if ( !$db ) {
	exit("<p>Que pasa, amigo!? I can't read from or write to the database! Do you have a writable ./db/ folder? <strong>No bueno!</strong></p>");
}

// Everything. UTF-8. Always. Everywhere.
mb_internal_encoding('UTF-8');
header('Content-type: text/html; charset=utf-8');

// Env constants
define('AJAX', strtolower(@$_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest');
define('MOBILE', is_int(strpos(strtolower($_SERVER['HTTP_USER_AGENT']), 'mobile')));

// Load config structure
require 'inc.config.php';
$cfg = new Config;

// Verify db schema
if ( !$cfg->last_db_schema_sync || $cfg->last_db_schema_sync < strtotime('-1 hour') ) {
	$schema = require 'inc.db-schema.php';
<?php

require_once __DIR__ . '/include/inc.cls.db_sqlite.php';
require_once __DIR__ . '/inc.functions.php';
header('Content-type: text/html; charset=utf-8');
header('X-XSS-Protection: 0');
$master = db_sqlite::open(__DIR__ . '/config/config.db');
if (!$master->connected()) {
    exit("Can't connect to master.");
}
// Better speed and no need for writable dirs.
$master->query('PRAGMA synchronous=OFF');
$master->query('PRAGMA journal_mode=OFF');
session_start();
function ensureMasterStructure($act = true)
{
    global $master;
    $schema = (require 'inc.db-schema.php');
    $mustExistTables = array_keys($schema['tables']);
    $exist = $master->select_fields('sqlite_master', 'tbl_name, tbl_name', array('type' => 'table', 'tbl_name' => $mustExistTables));
    if (count($exist) < count($mustExistTables)) {
        // No structure
        if (!$act) {
            exit("Can't setup master structure.");
        }
        foreach (array_diff_key($schema['tables'], $exist) as $tableName => $columns) {
            $master->createTable($tableName, $columns);
        }
        return ensureMasterStructure(false);
    }
    return true;
<?php

// Select db meta record
$objDb = $g_objUser->getAliasByAlias($_db);
if (!$objDb) {
    return missingParams(array('db'));
}
// Actual db connection
$db = db_sqlite::open($objDb->path);
if (!$db->connected()) {
    exit("Can't connect: " . html($db->error));
}
// set encoding
$db->query('PRAGMA encoding="UTF-8"');
// screw ACID, go SPEED!
$db->query('PRAGMA synchronous=OFF');
$db->query('PRAGMA journal_mode=OFF');
$g_objUser->loadAlias($objDb->alias);
<?php
// Init
error_reporting(E_ALL & ~E_STRICT);
header('Content-type: text/plain');
$start = microtime(1);
if ( isset($_GET['mysql']) ) {
        require '../db_mysql.php';
        $db = db_mysql::open(array('user' => $_GET['user'], 'pass' => $_GET['pass'], 'db' => $_GET['db']));
}
else {
        require '../db_sqlite.php';
        $db = db_sqlite::open(array('database' => './stuff.sqlite3'));
}
Exemple #5
0
<?php

require 'env.php';
$_start = microtime(1);
define('REQUEST_TIME', time());
header('Content-type: text/html; charset=utf-8');
define('BLOGSFEED_KEEP_BLOGS', 50);
// prerequisites
require WHERE_DB_GENERIC_AT . '/db_sqlite.php';
// db connection
$db = db_sqlite::open(array('database' => dirname(__FILE__) . '/db/blogs.sqlite3'));
if (!$db) {
    exit('No database connecto...');
}
// Screw ACID, go SPEED!
$db->execute('PRAGMA synchronous=OFF');
$db->execute('PRAGMA journal_mode=OFF');
require 'inc.args.php';
// db schema
$schema = (require 'inc.db-schema.php');
$db->schema($schema);
// class
spl_autoload_register(function ($class) {
    require __DIR__ . '/inc.' . strtolower($class) . '.php';
});
// template stuff
require 'inc.tpl.php';