Example #1
0
 public function connect()
 {
     if (!self::$connection) {
         self::$connection = mysql_connect($this->server, $this->username, $this->password);
     }
     mysql_select_db($this->db);
 }
Example #2
0
 public static function getInstance()
 {
     //get an instance of the connection
     if (Connection::$connection === NULL) {
         //if the connection is null
         // connect to the database local using the credentials
         $host = "localhost";
         $database = "CA1-TourBusMassacre";
         $username = "******";
         $password = "******";
         // connection for college database
         //            $host = "daneel";
         //            $database = "N00143233playground";
         //            $username = "******";
         //            $password = "******";
         $dsn = "mysql:host=" . $host . ";dbname=" . $database;
         //url for connection
         Connection::$connection = new PDO($dsn, $username, $password);
         //Connection is made with the variables above
         if (!Connection::$connection) {
             //if there is no connection
             die("Could not connect to database");
             //die
         }
     }
     return Connection::$connection;
     //return the connection from the credentials above
 }
Example #3
0
 public static function getInstance()
 {
     if (empty(self::$connection)) {
         self::$connection = new self();
         return self::$connection;
     }
 }
 public static function get()
 {
     if (self::$connection == false) {
         self::$connection = new PDO('mysql:host=' . self::$host . ';dbname=' . self::$dbname, self::$user, self::$pwd, array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES \'UTF8\'', PDO::ATTR_CASE => 'SET lc_time_names = \'fr_FR\''));
         return self::$connection;
     } else {
         return self::$connection;
     }
 }
Example #5
0
 protected static function open_connection()
 {
     //initialize connection
     self::$connection = new mysqli(self::$server, self::$user, self::$password, self::$database);
     //error in connection
     if (self::$connection->connect_errno) {
         echo 'Cannot connect to MySQL server : ' . self::$connection->connect_error;
         die;
     }
 }
Example #6
0
 public function connect()
 {
     if (!isset(self::$connection)) {
         //Filen .ini innehåller databasuppkopplingsinfo som databasnamn, lösenord m.m.
         $config = parse_ini_file('./config.ini');
         //denna fil läggs utanför den mappar användare kan nå för att skydda databasinfo
         self::$connection = new mysqli('localhost', $config['username'], $config['password'], $config['dbname']);
     }
     return self::$connection;
 }
Example #7
0
 public static function create($host, $dbname, $user, $pass)
 {
     if (self::$connection == null) {
         try {
             self::$connection = new PDO("mysql:host={$host};dbname={$dbname}", $user, $pass);
         } catch (PDOException $e) {
         }
     }
     return self::$connection;
 }
 /**
  * Connect to the database
  * 
  * @return bool false on failure / mysqli MySQLi object instance on success
  */
 public function connect()
 {
     if (!isset(self::$connection)) {
         $config = parse_ini_file(__DIR__ . '/../resources/dbconfig.ini');
         self::$connection = new mysqli($config['host'], $config['username'], $config['password'], $config['dbname']);
     }
     if (self::$connection === false) {
         return false;
     }
     return self::$connection;
 }
Example #9
0
 /**
  * Get the connection to the database
  */
 public static function get()
 {
     if (self::$connection == false) {
         try {
             self::$connection = new PDO('mysql:host=' . self::$host . ';dbname=' . self::$dbname, self::$user, self::$pwd, array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES \'UTF8\'', PDO::ATTR_CASE => 'SET lc_time_names = \'de_DE\'', PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION));
             return self::$connection;
         } catch (Exception $e) {
             echo "erreur de connexion : " . $e->getMessage();
         }
     } else {
         return self::$connection;
     }
 }
Example #10
0
 public function get()
 {
     $sql = $this->_select;
     try {
         $db = parent::connection();
         $stmt = $db->query($sql);
         $result = $stmt->fetchAll(PDO::FETCH_OBJ);
         $db = null;
         echo json_encode($result);
     } catch (PDOException $e) {
         echo '{"error":{"text":' . $e->getMessage() . '}}';
     }
 }
Example #11
0
 public function getUser($id)
 {
     $sql = $this->_select . " WHERE id = :id";
     try {
         $db = parent::connection();
         $stmt = $db->prepare($sql);
         $stmt->bindParam("id", $id);
         $stmt->execute();
         $result = $stmt->fetchObject();
         $db = null;
         echo json_encode($result);
     } catch (PDOException $e) {
         echo '{"error":{"text":' . $e->getMessage() . '}}';
     }
 }
Example #12
0
 public static function getInstance()
 {
     if (Connection::$connection === NULL) {
         // connect to the database
         $host = "localhost";
         $database = "photo_gallery";
         $username = "******";
         $password = "";
         $dsn = "mysql:host=" . $host . ";dbname=" . $database;
         Connection::$connection = new PDO($dsn, $username, $password);
         if (!Connection::$connection) {
             die("Could not connect to database");
         }
     }
     return Connection::$connection;
 }
Example #13
0
 public function get()
 {
     $sql = $this->_select . " LIMIT 1";
     try {
         $db = parent::connection();
         $stmt = $db->prepare($sql);
         $stmt->execute();
         $result = $stmt->fetchObject();
         $db = null;
         $result->info = preg_replace("'\r?\n'", '', $result->info);
         $result->info = stripslashes($result->info);
         $result->info = stripcslashes($result->info);
         echo json_encode($result);
     } catch (PDOException $e) {
         echo '{"error":{"text":' . $e->getMessage() . '}}';
     }
 }
 public static function getInstance()
 {
     if (Connection::$connection === NULL) {
         // connect to the database
         $host = "localhost";
         //logging into the database
         $db = "highland_books_database";
         $user = "******";
         $password = "******";
         $dsn = "mysql:host=" . $host . ";dbname=" . $db;
         Connection::$connection = new PDO($dsn, $user, $password);
         if (!Connection::$connection) {
             die("Could not connect to database");
         }
     }
     return Connection::$connection;
 }
 function descargaApk($array)
 {
     try {
         if ($array != NULL) {
             $con = new Connection();
             $mysql = $con->connection();
             $this->sql = "SELECT\n\t\t\t\taplicativo.ubicacion\n\t\t\t\tFROM usuarios\n\t\t\t\tINNER JOIN permisos on permisos.idUsuario = usuarios.id\n\t\t\t\tINNER JOIN aplicativo on aplicativo.id = permisos.idAplicativo\n\t\t\t\twhere\n\t\t\t\tusuarios.id = " . $array['usu'] . "\n\t\t\t\tand\n\t\t\t\taplicativo.id = " . $array['app'] . "\n\t\t\t\tand permisos.estado = 0";
             $resultado = mysql_query($this->sql);
             $fila = mysql_fetch_array($resultado);
             $con->disconnect($mysql);
         } else {
             $fila = $array;
         }
     } catch (Exception $e) {
         echo 'Excepción capturada: ', $e->getMessage(), "\n";
     }
     return $fila;
 }
Example #16
0
 public static function getInstance()
 {
     /* Creates new connection if connection doesn't already exist */
     if (Connection::$connection === NULL) {
         $host = 'localhost';
         //specify login details to phpmyadmin page
         $database = 'Yoink2';
         $username = '******';
         $password = '';
         $dsn = 'mysql:dbname=' . $database . ";host=" . $host;
         Connection::$connection = new PDO($dsn, $username, $password);
         if (!Connection::$connection) {
             //tests the connection
             die("Could not connect to database!");
         }
     }
     return Connection::$connection;
 }
Example #17
0
 public static function getInstance()
 {
     if (Connection::$connection === NULL) {
         // connect to the database local
         $host = "localhost";
         $database = "CA1-TourBusMassacre";
         $username = "******";
         $password = "******";
         // connection for college database
         //            $host = "daneel";
         //            $database = "N00143233playground";
         //            $username = "******";
         //            $password = "******";
         $dsn = "mysql:host=" . $host . ";dbname=" . $database;
         Connection::$connection = new PDO($dsn, $username, $password);
         if (!Connection::$connection) {
             die("Could not connect to database");
         }
     }
     return Connection::$connection;
 }
Example #18
0
 private function Connect()
 {
     if (!self::$connection) {
         self::$connection = mysql_connect(Settings::Get('DB_SERVER'), Settings::Get('DB_USERNAME'), Settings::Get('DB_PASSWORD')) or die('Unable to connect: ' . mysql_error());
         mysql_select_db(Settings::Get('DB_DATABASE')) or die('Unable to select: ' . mysql_error());
     }
 }