public function test_getConnection()
 {
     /** === Setup Mocks === */
     $this->mResource->shouldReceive('getConnection')->andReturn($this->mConn);
     /** === Call and asserts  === */
     $res = $this->obj->getConnection();
     $this->assertInstanceOf(\Magento\Framework\DB\Adapter\AdapterInterface::class, $res);
 }
Exemple #2
0
 public static function getNewsList()
 {
     // Запрос к БД
     $conn = Db::getConnection();
     $newsList = array();
     $sql = 'SELECT id, title, date, short_content ' . 'FROM news ' . 'ORDER BY date DESC ';
     $stmt = $conn->prepare($sql);
     //dayardayt
     /* execute prepared statement */
     $stmt->execute();
     //zapros
     $stmt->store_result();
     // zapros
     if ($stmt->num_rows > 0) {
         $stmt->bind_result($id, $title, $date, $sh_content);
         // kelgen maanini yigarat
         // output data of each row
         $i = 0;
         while ($row = $stmt->fetch()) {
             $newsList[$i]['id'] = $id;
             $newsList[$i]['title'] = $title;
             $newsList[$i]['date'] = $date;
             $newsList[$i]['sh_content'] = $sh_content;
             $i++;
         }
     }
     return $newsList;
 }
 public static function getNewsList()
 {
     //запрос к БД
     $db = Db::getConnection();
     //вызываем метод с параметрами подкдючения к базе данных
     $newsList = array();
     //Создем пустой масив для сохранения результатов
     $result = $db->query('SELECT id,title,date,short_content FROM news LIMIT 4');
     //Нужний запрос к БД
     if (!$result) {
         die("Execute query error");
     }
     $i = 0;
     while ($row = $result->fetch(true)) {
         // $row -символизирует строку из базы даных
         //В цикле мы записываем необходимые даные в масив результатов
         $newsList[$i]['id'] = $row['id'];
         $newsList[$i]['title'] = $row['title'];
         $newsList[$i]['date'] = $row['date'];
         $newsList[$i]['short_content'] = $row['short_content'];
         $i++;
     }
     return $newsList;
     //Возвращаем масив
 }
 public function check()
 {
     $username = $_POST['username'];
     $password = $_POST['password'];
     $conn = Db::getConnection();
     $sql = "SELECT username, password, admin\n\t\t\t\tFROM users\n\t\t\t\tWHERE username = '******'";
     $q = $conn->prepare($sql);
     $q->execute();
     $users = $q->fetch(\PDO::FETCH_ASSOC);
     //var_dump($users);die('  proba');
     $logger = new Logger();
     $error = $logger->checkCredentials($password, $users);
     //$isAdmin = $logger->checkAdmin($password,$users);
     //var_dump($error);die('   ajde vise!!!');
     if ($error) {
         //echo '<pre>'; var_dump($error);die(); echo '</pre>';
         $html = new Html($this->controllerName);
         $html->error = $error;
         //echo '<pre>'; var_dump($html->error);die(); echo '</pre>';
         $html->render('index');
     } else {
         $user = new User($users['username'], $users['admin']);
         $user->login();
         //var_dump($user);die('   jebem li ga');
         header('Location: /');
     }
 }
 public static function Reg($reg_name, $reg_surname, $reg_phone, $reg_email, $reg_location, $reg_password_hash, $reg_avatar)
 {
     $db = Db::getConnection();
     $query = $db->prepare("INSERT INTO registration (reg_id, reg_name, reg_surname, reg_date, reg_phone, reg_email, reg_location, reg_password_hash, vk_account, reg_avatar) \n\t\t\t\t\t\t\t\tVALUES (NULL, :reg_name, :reg_surname, CURRENT_TIMESTAMP, :reg_phone, :reg_email, :reg_location, :reg_password_hash, 0, :reg_avatar);");
     $query->execute(array('reg_name' => "{$reg_name}", 'reg_surname' => "{$reg_surname}", 'reg_phone' => "{$reg_phone}", 'reg_email' => "{$reg_email}", 'reg_location' => "{$reg_location}", 'reg_password_hash' => "{$reg_password_hash}", 'reg_avatar' => "{$reg_avatar}"));
     return $query;
 }
 public function create()
 {
     $firstname = $_POST['firstname'];
     $lastname = $_POST['lastname'];
     $email = $_POST['email'];
     $username = $_POST['username'];
     $password = password_hash($_POST['password'], PASSWORD_BCRYPT);
     $conn = Db::getConnection();
     $sql = "SELECT *\n\t\t\t\tFROM users";
     $q = $conn->prepare($sql);
     $q->execute();
     $users = $q->fetchAll(\PDO::FETCH_ASSOC);
     $validator = new Validator();
     $error = $validator->validateRegisterForm($_POST, $users);
     //echo '<pre>'; var_dump($error); echo '</pre>';die();
     if ($error) {
         //echo '<pre>'; var_dump($error);die(); echo '</pre>';
         $html = new Html($this->controllerName);
         $html->error = $error;
         //echo '<pre>'; var_dump($html->error);die(); echo '</pre>';
         //;kweojn'dlfv'dlfkv
         $html->render('index');
     } else {
         $newUserSql = "INSERT INTO users\n\t\t\t(`firstname`, `lastname`, `email`, `username`, `password`, `admin`)\n\t\t\tVALUES\n\t\t\t('{$firstname}', '{$lastname}', '{$email}', '{$username}', '{$password}', '0')";
         $q = $conn->prepare($newUserSql);
         $q->execute();
         header('Location: /login/index');
     }
 }
Exemple #7
0
 public static function getTotalProductsInCategory($categoryId)
 {
     $db = Db::getConnection();
     $result = $db->query('SELECT count(id) AS count FROM product ' . 'WHERE status="1" AND category_id ="' . $categoryId . '"');
     $result->setFetchMode(PDO::FETCH_ASSOC);
     $row = $result->fetch();
     return $row['count'];
 }
 public static function GetInfo($reg_id)
 {
     $db = Db::getConnection();
     $query = $db->prepare("SELECT * FROM registration WHERE reg_id = :reg_id;");
     $query->execute(array('reg_id' => "{$reg_id}"));
     $result = $query->fetch();
     return $result;
 }
Exemple #9
0
 public static function addUser($login, $password)
 {
     $db = Db::getConnection();
     $sql = 'INSERT INTO users (login, password) VALUES (:login, :password)';
     $result = $db->prepare($sql);
     $result->bindParam(':login', $login, PDO::PARAM_INT);
     $result->bindParam(':password', $password, PDO::PARAM_INT);
     $result->execute();
     return $result->execute();
 }
Exemple #10
0
 static function table($with_db_name = true)
 {
     $conn = Db::getConnection('streams');
     $prefix = empty($conn['prefix']) ? '' : $conn['prefix'];
     $table_name = $prefix . 'notification';
     if (!$with_db_name) {
         return $table_name;
     }
     $db = Db::connect('streams');
     return $db->dbName() . '.' . $table_name;
 }
Exemple #11
0
 public static function checkEmailExists($email)
 {
     $db = Db::getConnection();
     $sql = 'SELECT COUNT(*) FROM user WHERE email = :email';
     $result = $db->prepare($sql);
     $result->bindParam(':email', $email, PDO::PARAM_STR);
     $result->execute();
     if ($result->fetchColumn()) {
         return true;
     }
     return false;
 }
 public static function amIAdmin($get_reg_id)
 {
     $db = Db::getConnection();
     $query = $db->prepare("SELECT is_admin FROM registration WHERE reg_id = :reg_id;");
     $query->execute(array('reg_id' => "{$get_reg_id}"));
     $result = $query->fetch();
     if ($result['is_admin'] == 1) {
         return True;
     } else {
         return False;
     }
 }
Exemple #13
0
 public static function getCategoriesList()
 {
     $db = Db::getConnection();
     $categoryList = array();
     $result = $db->query('SELECT id, name FROM category ' . 'ORDER BY sort_order ASC');
     $i = 0;
     while ($row = $result->fetch()) {
         $categoryList[$i]['id'] = $row['id'];
         $categoryList[$i]['name'] = $row['name'];
         $i++;
     }
     return $categoryList;
 }
Exemple #14
0
 /**
  * Return array with list of works
  * @return array
  */
 public static function getList()
 {
     $db = Db::getConnection();
     $list = array();
     $result = $db->query('SELECT title, link FROM base WHERE type="uslugi"');
     $i = 0;
     while ($row = $result->fetch()) {
         $list[$i]['title'] = $row['title'];
         $list[$i]['link'] = $row['link'];
         $i++;
     }
     return $list;
 }
Exemple #15
0
 /**
  * Returns an array of categories
  */
 public static function getCategoriesList()
 {
     $db = Db::getConnection();
     $categoryList = array();
     $result = $db->prepare('SELECT id, name FROM category ORDER BY sort_order ASC');
     $result->execute();
     $row = $result->fetchAll(PDO::FETCH_ASSOC);
     for ($i = 0; $i < count($row); $i++) {
         $categoryList[$i]['id'] = $row[$i]['id'];
         $categoryList[$i]['name'] = $row[$i]['name'];
     }
     return $categoryList;
 }
Exemple #16
0
 public static function sendPost($title, $short_content, $content, $author_name)
 {
     $db = Db::getConnection();
     $sql = 'INSERT INTO posts (title, short_content, content, author_name) ' . 'VALUE(:title, :short_content, :content, :author_name)';
     $result = $db->prepare($sql);
     $result->bindParam(":title", $title, PDO::PARAM_STR);
     $result->bindParam(":short_content", $short_content, PDO::PARAM_STR);
     $result->bindParam(":content", $content, PDO::PARAM_STR);
     $result->bindParam(":author_name", $author_name, PDO::PARAM_STR);
     $result->execute();
     $lastId = $db->lastInsertId();
     return $lastId;
 }
Exemple #17
0
 public static function getShortDescription($type)
 {
     $db = Db::getConnection();
     $description = array();
     $result = $db->query("SELECT title, description FROM base WHERE type='{$type}'");
     $i = 0;
     while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
         $description[$i]['title'] = $row['title'];
         $description[$i]['description'] = $row['description'];
         $i++;
     }
     return $description;
 }
Exemple #18
0
 public static function getCategoryList()
 {
     $db = Db::getConnection();
     $categoryList = array();
     $result = $db->query('SELECT id, name FROM category WHERE status = "1" ORDER BY sort_order, name ASC');
     $i = 0;
     // var_dump($result);
     while ($row = $result->fetch()) {
         $categoryList[$i] = array('id' => $row['id'], 'name' => $row['name']);
         $i++;
     }
     return $categoryList;
 }
Exemple #19
0
 public static function checkUserData($email, $password)
 {
     $db = Db::getConnection();
     $sql = 'SELECT * FROM user WHERE email = :email AND password = :password';
     $result = $db->prepare($sql);
     $result->bindParam(':email', $email, PDO::PARAM_INT);
     $result->bindParam(':password', $password, PDO::PARAM_INT);
     $result->execute();
     $user = $result->fetch();
     if ($user) {
         return $user['id'];
     }
     return false;
 }
Exemple #20
0
 public static function ViewItemById($id)
 {
     $id = intval($id);
     if ($id) {
         $db = Db::getConnection();
         $sql = 'SELECT * FROM posts WHERE id= :id';
         $result = $db->prepare($sql);
         $result->bindParam(":id", $id, PDO::PARAM_INT);
         $result->setFetchMode(PDO::FETCH_ASSOC);
         $result->execute();
         $Item = $result->fetch();
         return $Item;
     }
 }
 public static function getNewsList()
 {
     $db = Db::getConnection();
     $newsList = array();
     $result = $db->query('SELECT `id`, `title`, `date`,`short_content` FROM `news` ORDER BY `date` DESC LIMIT 10');
     $i = 0;
     while ($row = $result->fetch()) {
         $newsList[$i]['id'] = $row['id'];
         $newsList[$i]['title'] = $row['title'];
         $newsList[$i]['date'] = $row['date'];
         $newsList[$i]['short_content'] = $row['short_content'];
         $i++;
     }
     return $newsList;
 }
Exemple #22
0
 /**
  * Returns an array of news item
  */
 public static function getNewsList()
 {
     $db = Db::getConnection();
     $newsList = array();
     $result = $db->query('SELECT id, title, date, short_content ' . 'FROM news ' . 'ORDER BY date DESC ' . 'LIMIT 10');
     $i = 0;
     while ($row = $result->fetch()) {
         $newsList[$i]['id'] = $row['id'];
         $newsList[$i]['title'] = $row['title'];
         $newsList[$i]['date'] = $row['date'];
         $newsList[$i]['short_content'] = $row['short_content'];
         $i++;
     }
     return $newsList;
 }
Exemple #23
0
 public function index()
 {
     $conn = Db::getConnection();
     $articleModel = new Article();
     $firstFiveArticles = $articleModel->getArticles($conn, 5);
     //var_dump($firstFiveArticles);die('lele');
     foreach ($firstFiveArticles as &$article) {
         $article['time'] = $articleModel->formatArticleDate($article["time"]);
         //date("d.m.Y H:i",strtotime($article["time"]))
     }
     $html = new Html($this->controllerName);
     $html->firstFiveArticles = $firstFiveArticles;
     $html->render('home');
     //var_dump($result);die();
 }
Exemple #24
0
 /**
  * Retrieve the table name to use in SQL statement
  * @method table
  * @static
  * @param {boolean} [$with_db_name=true] Indicates wheather table name should contain the database name
  * @return {string|Db_Expression} The table name as string optionally without database name if no table sharding
  * was started or Db_Expression class with prefix and database name templates is table was sharded
  */
 static function table($with_db_name = true)
 {
     if (Q_Config::get('Db', 'connections', 'Metrics', 'indexes', 'Session', false)) {
         return new Db_Expression(($with_db_name ? '{$dbname}.' : '') . '{$prefix}' . 'session');
     } else {
         $conn = Db::getConnection('Metrics');
         $prefix = empty($conn['prefix']) ? '' : $conn['prefix'];
         $table_name = $prefix . 'session';
         if (!$with_db_name) {
             return $table_name;
         }
         $db = Db::connect('Metrics');
         return $db->dbName() . '.' . $table_name;
     }
 }
Exemple #25
0
 /**
  * Returns an array of recommended products
  */
 public static function getRecommendedProducts()
 {
     $db = Db::getConnection();
     $productsList = array();
     $result = $db->query('SELECT id, name, price, image, is_new FROM product ' . 'WHERE status = "1" AND is_recommended = "1"' . 'ORDER BY id DESC ');
     $i = 0;
     while ($row = $result->fetch()) {
         $productsList[$i]['id'] = $row['id'];
         $productsList[$i]['name'] = $row['name'];
         $productsList[$i]['image'] = $row['image'];
         $productsList[$i]['price'] = $row['price'];
         $productsList[$i]['is_new'] = $row['is_new'];
         $i++;
     }
     return $productsList;
 }
Exemple #26
0
 /**
  * Returns an array of blog items
  */
 public static function getBlogList()
 {
     $db = Db::getConnection();
     $blogList = array();
     $result = $db->prepare('SELECT id, title, date, short_content FROM blog ORDER BY date DESC LIMIT 3');
     $result->execute();
     $i = 0;
     while (($row = $result->fetch_assoc()) != false) {
         $blogList[$i]['id'] = $row['id'];
         $blogList[$i]['title'] = $row['title'];
         $blogList[$i]['date'] = $row['date'];
         $blogList[$i]['short_content'] = $row['short_content'];
         $i++;
     }
     return $blogList;
 }
Exemple #27
0
 public static function getTopList()
 {
     $db = Db::getConnection();
     $topList = array();
     $result = $db->query('SELECT id, title, date, short_content, author_name ' . 'FROM posts ' . 'ORDER BY title DESC ' . 'LIMIT 3');
     $i = 0;
     while ($row = $result->fetch()) {
         $topList[$i]['id'] = $row['id'];
         $topList[$i]['title'] = $row['title'];
         $topList[$i]['data'] = $row['date'];
         $topList[$i]['short_content'] = $row['short_content'];
         $topList[$i]['author_name'] = $row['author_name'];
         $i++;
     }
     return $topList;
 }
 public function tag($tag)
 {
     //die($type);
     $conn = Db::getConnection();
     //U tabeli tags treba naci id od prosledjenog taga $search,
     //nakon toga naci u tabeli articles-tags id-ove svih articles
     //koji imaju taj search
     $sql = "SELECT articles.id, time, title, img, teaser\n\t\t\t\tFROM articles\n\t\t\t\t  JOIN articles_tags ON articles.id = article_id\n\t\t\t\t  JOIN tags ON tag_id = tags.id\n\t\t\t\tWHERE tags.name = '{$tag}'";
     $q = $conn->prepare($sql);
     $q->execute();
     $articlesByTags = $q->fetchAll(\PDO::FETCH_ASSOC);
     //var_dump($tagIdsArray);die('       da vidimo!!!');
     $html = new Html($this->controllerName);
     $html->articlesByTags = $articlesByTags;
     $html->render('tag');
 }
    public function getSubCategoriesListAdmin()
    {
        $db = Db::getConnection();
        $id = self::getCategoriesListAdmin();
        $result = $db->query('SELECT `id`,`title`,`id_scategories`
							FROM `sub_categories`');
        $subCategotyList = array();
        $i = 0;
        while ($row = $result->fetch()) {
            $subCategotyList[$i]['id'] = $row['id'];
            $subCategotyList[$i]['title'] = $row['title'];
            $subCategotyList[$i]['id_scategories'] = $row['id_scategories'];
            $i++;
        }
        return $subCategotyList;
    }
    public static function save($userName, $userPhone, $userCity, $userAddress, $userComment, $userId, $products)
    {
        $db = Db::getConnection();
        $sql = 'INSERT INTO product_order (user_name,user_phone,user_city,user_address,user_comment,id_user,products)
		   		   VALUES (:user_name, :user_phone,:user_city,:user_address,:user_comment, :user_id, :products)';
        $products = json_encode($products);
        $result = $db->prepare($sql);
        $result->bindParam(':user_name', $userName, PDO::PARAM_STR);
        $result->bindParam(':user_phone', $userPhone, PDO::PARAM_STR);
        $result->bindParam(':user_city', $userCity, PDO::PARAM_STR);
        $result->bindParam(':user_address', $userAddress, PDO::PARAM_STR);
        $result->bindParam(':user_comment', $userComment, PDO::PARAM_STR);
        $result->bindParam(':user_id', $userId, PDO::PARAM_STR);
        $result->bindParam(':products', $products, PDO::PARAM_STR);
        return $result->execute();
    }