Example #1
0
 public static function connect($host, $user, $password, $database)
 {
     if (!isset(self::$conn)) {
         self::$conn = @new PDO("mysql:host={$host}; dbname={$database}", $user, $password, self::$settings);
     }
     return self::$conn;
 }
Example #2
0
 public function __construct()
 {
     require_once './config/Config.php';
     $config = Config::getConfig();
     if (self::$conn == null) {
         self::$conn = mysqli_connect($config['host'], $config['username'], $config['password'], $config['dbname']);
     }
 }
 public static function instance()
 {
     if (!isset(self::$conn)) {
         self::$conn = new mysqli(MYSQL_HOST, MYSQL_USER, MYSQL_PWD, MYSQL_DB, MYSQL_PORT);
         if (self::$conn->connect_error) {
             die("Connection failed: " . self::$conn->connect_error);
         }
     }
     return self::$conn;
 }
 /**
  *
  * @return PDO
  */
 function getConnection()
 {
     if (self::$conn === null) {
         try {
             self::$conn = new PDO('mysql:host=localhost;dbname=oneat;charset=utf8', 'root', 'likrysz1');
         } catch (PDOException $ex) {
             echo $ex;
         }
     }
     return self::$conn;
 }
 private static function connect()
 {
     if (self::$cnt == false) {
         if (!isset($GLOBALS['database_host'])) {
             self::$conn = new MongoClient('localhost');
         } else {
             self::$conn = new MongoClient("mongodb://" . $GLOBALS['database_user'] . ":" . $GLOBALS['database_password'] . "@" . $GLOBALS['database_host']);
         }
         self::$cnt = true;
     } else {
         return false;
     }
 }
Example #6
0
 function Open()
 {
     global $db_user;
     // defined in db_passwd.php
     global $db_pass;
     // defined in db_passwd.php
     self::$user = $db_user;
     self::$pass = $db_pass;
     self::$conn = new mysqli('db.takethegrt.ca', self::$user, self::$pass, 'grt_info');
     if (mysqli_connect_errno()) {
         throw new Exception('Connect failed: ' . mysqli_connect_error());
     }
 }
<?php

require_once __DIR__ . '/commons/database-connection.php';
try {
    $db = new Database();
    $mongo = $db->conn();
} catch (Exception $e) {
    $res = ['conn' => false, 'msg' => ['text' => $e->getMessage(), 'color' => '#FF0000']];
    exit(json_encode($res));
}
// TODO
$docs = $mongo->goldstarDB->movies->find();
$movies = [];
foreach ($docs as $item) {
    $movies[] = ['_id' => $item['_id'], 'shortTitle' => $item['shortTitle'], 'IntTitle' => isset($item['IntTitle']) ? $item['IntTitle'] : null, 'Title' => isset($item['Title']) ? $item['Title'] : null, 'mediaFormat' => isset($item['mediaFormat']) ? $item['mediaFormat'] : null, 'ReleaseDate' => isset($item['ReleaseDate']) ? date('d-m-Y', $item['ReleaseDate']->sec) : null];
}
echo json_encode($movies);
Example #8
0
 function extendAuthentication($ticket)
 {
     $db = new Database('tazapi');
     $db->open();
     $dateTime = new DateTime('+1 hour', new DateTimeZone('Europe/Vilnius'));
     $expires = $dateTime->format('Y-m-d H:i:s');
     $sql = "UPDATE tickets SET expires='" . $expires . "' WHERE ticket = '" . $ticket . "';";
     $db->conn()->query($sql);
     $db->close();
 }
 public function __construct()
 {
     $loadDB = new Database();
     $this->db = $loadDB->conn($this->database);
 }
Example #10
0
 public static function disconnect()
 {
     self::$conn = null;
 }
Example #11
0
 public static function connect($host, $database, $user, $pass, $charset = 'utf8')
 {
     self::$conn = new \PDO('mysql:host=' . $host . ';dbname=' . $database . ';charset=' . $charset, $user, $pass);
     self::$conn->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
 }
 public function disconnet()
 {
     self::$conn = null;
 }
 /**
  * This method is called when the file is included.
  * It is used to connect to the database.
  * Also to set @property conn to new PDO.
  *
  * @method init
  * @public
  * @static
  */
 public static function init()
 {
     $string = file_get_contents(dirname(__DIR__) . '/env.json');
     $data = json_decode($string, true);
     $connData = $data['database'];
     self::$conn = new PDO('mysql:host=' . $connData['servername'] . ';dbname=' . $connData['database'], $connData['username'], $connData['password']);
 }