add block model

This commit is contained in:
ghost 2021-12-28 21:59:34 +02:00
parent 4b0964f15b
commit ca02840074
2 changed files with 48 additions and 0 deletions

View File

@ -0,0 +1,37 @@
<?php
class ModelBlock extends Model {
public function getNextBlock() {
try {
$query = $this->_db->query("SELECT COUNT(*) + 1 AS `nextBlock` FROM `block`");
return $query->fetch()['nextBlock'];
} catch (PDOException $e) {
trigger_error($e->getMessage());
return false;
}
}
public function addBlock(int $hash, int $time) {
try {
$query = $this->_db->prepare("INSERT INTO `block` SET `hash` = ?,
`time` = ?");
$query->execute([$hash, $time]);
$this->_db->lastInsertId();
} catch (PDOException $e) {
trigger_error($e->getMessage());
return false;
}
}
}

View File

@ -4,6 +4,7 @@
require('config.php');
require(PROJECT_DIR . '/application/model/model.php');
require(PROJECT_DIR . '/application/model/block.php');
require(PROJECT_DIR . '/application/model/user.php');
require(PROJECT_DIR . '/system/curl.php');
@ -31,6 +32,16 @@ $_modelUser = new ModelUser(
DB_PASSWORD
);
/*
$_modelBlock = new ModelBlock(
DB_DATABASE,
DB_HOST,
DB_PORT,
DB_USER,
DB_PASSWORD
);
*/
// Route
if (isset($_GET['_route_'])) {