Пример #1
0
 public static function getThreeLastRecord(int $limit)
 {
     $sql = 'SELECT * FROM ' . static::TABLE . ' ORDER BY id DESC LIMIT ' . $limit;
     //var_dump($sql);
     $db = new Db();
     return $db->query($sql, static::class);
 }
Пример #2
0
 /**
  * Function to create new task, validate and save it to DB
  * @param $new_task - user input - task
  */
 public function createNewTask($new_task)
 {
     $new_task = Validate::cleanInput($new_task);
     if ($new_task != "") {
         //not to allow to add empty task
         $conn = Model\Db::getConnection();
         $query_to_create_new_task = 'INSERT INTO `task`(`date`, `name`, `is_done`, `is_deleted`, `time`) VALUES (?, ?, ?, ?, ?)';
         $stmt = $conn->prepare($query_to_create_new_task);
         $stmt->bindParam(1, $date);
         $stmt->bindParam(2, $name);
         $stmt->bindParam(3, $is_done);
         $stmt->bindParam(4, $is_deleted);
         $stmt->bindParam(5, $time);
         $stmt->execute();
         $date = date("Y-m-d");
         $name = $new_task;
         $is_done = 0;
         $is_deleted = 0;
         $time = date("H:i:s");
         $stmt->execute();
     }
 }
Пример #3
0
<?php

use Model\Db;
use Model\table\News;
require __DIR__ . '/../autoload.php';
$test = new Db();
//var_dump($test);
/*
Вывод на экран var_dump($test);
object(Model\Db)#1 (1) {
  ["dbh":protected]=>
  object(PDO)#2 (0) {
  }
}
*/
$sqlOne = 'SELECT * FROM users';
//var_dump($sqlOne); //проверка на корректность запроса
/*
Вывод на экран var_dump($sql);
string(19) "SELECT * FROM users"
*/
$sqlTwo = 'SELECT * FROM users WHERE id=:id';
//var_dump($sqlTwo);
/*
Вывод на экран var_dump($sql);
string(32) "SELECT * FROM users WHERE id=:id"
*/
$mass = [':id' => 1];
//var_dump($mass);
/*
Вывод на экран var_dump($mass);