Browse Source

init sqlite edition

pull/8/head
ghost 3 years ago
parent
commit
808b11fb7d
  1. 8
      config-default.php
  2. 6
      library/sqlite.php
  3. 4
      public/index.php

8
config-default.php

@ -6,13 +6,11 @@ ini_set('display_startup_errors', '1');
error_reporting(E_ALL); error_reporting(E_ALL);
// Application // Application
define('BASE_URL', 'https://kvazar.ml'); define('BASE_URL', '/');
define('PAGE_LIMIT', 10); define('PAGE_LIMIT', 10);
define('SEF_MODE', true); define('SEF_MODE', false);
// Database // Database
define('DB_HOST', 'localhost'); define('DB_NAME', 'kvazar.dat');
define('DB_PORT', '3306');
define('DB_NAME', '');
define('DB_USERNAME', ''); define('DB_USERNAME', '');
define('DB_PASSWORD', ''); define('DB_PASSWORD', '');

6
library/mysql.php → library/sqlite.php

@ -1,12 +1,12 @@
<?php <?php
class MySQL { class SQLite {
public function __construct() { public function __construct($database, $username, $password) {
try { try {
$this->_db = new PDO('mysql:dbname=' . DB_NAME . ';host=' . DB_HOST . ';port=' . DB_PORT . ';charset=utf8', DB_USERNAME, DB_PASSWORD, [PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8']); $this->_db = new PDO('sqlite:' . $database, $username, $password, [PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8']);
$this->_db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $this->_db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$this->_db->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC); $this->_db->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
$this->_db->setAttribute(PDO::ATTR_TIMEOUT, 600); $this->_db->setAttribute(PDO::ATTR_TIMEOUT, 600);

4
public/index.php

@ -2,7 +2,7 @@
require_once('../config.php'); require_once('../config.php');
require_once('../library/icon.php'); require_once('../library/icon.php');
require_once('../library/mysql.php'); require_once('../library/sqlite.php');
$query = isset($_GET['q']) ? $_GET['q'] : false; $query = isset($_GET['q']) ? $_GET['q'] : false;
$ns = isset($_GET['ns']) ? preg_replace('/[^a-zA-Z0-9]+/', '', $_GET['ns']) : false; $ns = isset($_GET['ns']) ? preg_replace('/[^a-zA-Z0-9]+/', '', $_GET['ns']) : false;
@ -38,7 +38,7 @@ if ($page > 0) {
$limit = PAGE_LIMIT * $page; $limit = PAGE_LIMIT * $page;
} }
$db = new MySQL(); $db = new SQLite(DB_NAME, DB_USERNAME, DB_PASSWORD);
if ($ns) { if ($ns) {
$namespaceValue = $db->getNamespaceName($ns); $namespaceValue = $db->getNamespaceName($ns);

Loading…
Cancel
Save