Add my template project
This commit is contained in:
19
engine/class/0000.root.php
Normal file
19
engine/class/0000.root.php
Normal file
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
class Root {
|
||||
private static $installed = false;
|
||||
|
||||
public static function init() {
|
||||
self::$installed = floatval(file_get_contents(__RD__.'installed'));
|
||||
}
|
||||
|
||||
public static function url($url, $force = true) {
|
||||
header('Location: '.$url);
|
||||
if($force) exit();
|
||||
}
|
||||
|
||||
public static function installed() {
|
||||
return self::$installed;
|
||||
}
|
||||
}
|
||||
|
||||
Root::init();
|
60
engine/class/0001.db.php
Normal file
60
engine/class/0001.db.php
Normal file
@ -0,0 +1,60 @@
|
||||
<?php
|
||||
class DB {
|
||||
private static $pdos = [];
|
||||
|
||||
public static function init($conf = []) {
|
||||
try {
|
||||
foreach($conf as $title => $data) {
|
||||
$dsn = sprintf('%s:dbname=%s;host=%s;port=%d;charset=%s',
|
||||
$data['driver'],
|
||||
$data['name'],
|
||||
$data['host'],
|
||||
$data['port'],
|
||||
$data['charset']
|
||||
);
|
||||
self::$pdos[$title] = new PDO($dsn, $data['user'], $data['password'], $data['options']);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
catch(\Throwable $th) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static function getQuery($db, $sql, $args = null) {
|
||||
if(!is_array($args) && !empty($args))
|
||||
$args = [$args];
|
||||
|
||||
$stmt = self::$pdos[$db]->prepare($sql);
|
||||
|
||||
try {
|
||||
$stmt->execute($args);
|
||||
}
|
||||
catch(\Throwable $th) {
|
||||
Debug::print($sql);
|
||||
Debug::print($args);
|
||||
Debug::print($th);
|
||||
}
|
||||
|
||||
if(stristr($sql, 'SELECT'))
|
||||
return $stmt->fetch(PDO::FETCH_OBJ);
|
||||
|
||||
if(stristr($sql, 'INSERT'))
|
||||
return self::$pdos[$db]->lastInsertId();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function getQueryAll($db, $sql, $args = null) {
|
||||
if(!is_array($args) && !empty($args))
|
||||
$args = [$args];
|
||||
|
||||
$stmt = self::$pdos[$db]->prepare($sql);
|
||||
$stmt->execute($args);
|
||||
return $stmt->fetchAll(PDO::FETCH_OBJ);
|
||||
}
|
||||
}
|
||||
|
||||
if(!DB::init($config['db'])) {
|
||||
die('DB not connected! Recheck configs!');
|
||||
}
|
37
engine/class/0002.debug.php
Normal file
37
engine/class/0002.debug.php
Normal file
@ -0,0 +1,37 @@
|
||||
<?php
|
||||
// REQUIREMENTS:
|
||||
// 0001.db.php
|
||||
|
||||
class Debug {
|
||||
public static function init() {
|
||||
if(!Root::installed())
|
||||
self::createTables();
|
||||
}
|
||||
|
||||
public static function createTables() {
|
||||
DB::getQuery('main',
|
||||
'CREATE TABLE IF NOT EXISTS `debug_log` (
|
||||
`id` INT(11) NOT NULL AUTO_INCREMENT,
|
||||
`value` TEXT CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
)
|
||||
ENGINE = InnoDB
|
||||
CHARSET=utf8
|
||||
COLLATE utf8_general_ci'
|
||||
);
|
||||
}
|
||||
|
||||
public static function print($a, $b = false) {
|
||||
echo '<pre>';
|
||||
$b ? var_dump($a) : print_r($a);
|
||||
echo '</pre>';
|
||||
}
|
||||
|
||||
public static function log($string) {
|
||||
$string = date('H:i:s d.m.Y', time()).' | '.$string;
|
||||
DB::getQuery('main', 'INSERT INTO `debug_log` (`value`) VALUES (?)', $string);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// Debug::init();
|
Reference in New Issue
Block a user