예제 #1
0
 private function setAddressBookModel($recordId = null)
 {
     $db = DbConfig::getInstance();
     if ($recordId == null) {
         $query = $db->prepare("SELECT * FROM address_book ORDER BY name DESC");
         $query->execute();
         if ($results = $query->fetchAll()) {
             self::$data['contacts'] = $results;
         }
     } else {
         $query = $db->prepare("SELECT * FROM address_book WHERE id = ? LIMIT 1");
         $query->execute([$recordId]);
         $result = $query->fetch();
         self::$data['data']['name'] = $result['name'];
         self::$data['data']['id'] = $result['id'];
         self::$data['data']['surname'] = $result['surname'];
         self::$data['data']['phone'] = $result['phone'];
         self::$data['data']['address'] = $result['address'];
     }
 }
예제 #2
0
파일: Home.php 프로젝트: masteruser20/Blog
 private function setHomeModel($page, $category)
 {
     $db = DbConfig::getInstance();
     if (!$page) {
         if (!$category) {
             $query = $db->prepare("SELECT * FROM posts ORDER BY date DESC LIMIT 10");
         } else {
             $query = $db->prepare("SELECT * FROM posts where categories_id = ? ORDER BY date DESC LIMIT 10");
         }
     } else {
         $start = ($page - 1) * 10;
         self::$data['activePage'] = $page;
         if (!$category) {
             $query = $db->prepare("SELECT * FROM posts ORDER BY date DESC  LIMIT {$start},10");
         } else {
             $query = $db->prepare("SELECT * FROM posts WHERE  categories_id = ? ORDER BY date DESC  LIMIT {$start},10");
         }
     }
     if ($category) {
         $query->execute([$category]);
     } else {
         $query->execute();
     }
     self::$data['articles'] = $query->fetchAll();
     foreach (self::$data['articles'] as &$article) {
         $article['text'] = $this->toBB($article['text']);
     }
     if (!$category) {
         $query = $db->prepare("SELECT COUNT(*) FROM posts");
         $query->execute();
     } else {
         $query = $db->prepare("SELECT COUNT(*) FROM posts where categories_id = ?");
         $query->execute([$category]);
     }
     $result = $query->fetch();
     self::$data['articlesCount'] = $result[0];
     self::$data['pages'] = ceil((int) $result[0] / 10);
 }
예제 #3
0
<?php

header("Content-Type: application/json", true);
require 'DbConfig.php';
$error = null;
$success = false;
$data = [];
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    $db = DbConfig::getInstance();
    if ($_POST['action'] === 'search') {
        if (isset($_POST['text']) && strlen($_POST['text']) > 2) {
            $query = $db->prepare('SELECT * FROM address_book WHERE
                    name LIKE :keyword OR
                    surname LIKE :keyword OR
                    phone LIKE  :keyword OR
                    address LIKE :keyword');
            $query->bindValue(':keyword', '%' . $_POST['text'] . '%');
            $query->execute();
            $results = $query->fetchAll();
            if (!empty($results)) {
                $data = $results;
                $success = true;
            }
        }
    } else {
        if (isset($_POST['data'])) {
            $_data = $_POST['data'];
            $qMarks = str_repeat('?,', count($_data) - 1) . '?';
            array_walk($_data, function (&$value) {
                $value = (int) $value;
            });
예제 #4
0
파일: index.php 프로젝트: masteruser20/Blog
 public static function DB()
 {
     return DbConfig::getInstance();
 }