Browse Source

add block model

main
ghost 3 years ago
parent
commit
ca02840074
  1. 37
      src/application/model/block.php
  2. 11
      src/bootstrap.php

37
src/application/model/block.php

@ -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;
}
}
}

11
src/bootstrap.php

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

Loading…
Cancel
Save