Esempio n. 1
0
 protected static function getConnection()
 {
     if (!self::$connection) {
         self::$connection = new PDO('mysql:host=' . DB_HOST . ';dbname=' . DB_NAME, DB_USER, DB_PASSWORD, [PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]);
     }
     return self::$connection;
 }
Esempio n. 2
0
 public static function getInstance()
 {
     if (!self::$connection) {
         self::$connection = new self();
     }
     return self::$connection;
 }
Esempio n. 3
0
 public function getTermInfo($condition)
 {
     $db = Db::connection($this->connection)->table($this->table);
     $db = $this->formatCondition($db, $condition);
     $res = $db->first();
     return $res;
 }
Esempio n. 4
0
 public static function connect($host, $database, $user, $password)
 {
     if (!isset(self::$connection)) {
         $dsn = "mysql:host={$host};dbname={$database}";
         self::$connection = new PDO($dsn, $user, $password, self::$options);
     }
 }
Esempio n. 5
0
 public static function connect($config)
 {
     self::$connection = @new mysqli($config['hostname'], $config['username'], $config['password'], $config['database']);
     if (self::$connection->connect_errno) {
         throw new Exception(self::$connection->connect_error);
     }
     self::execute("SET NAMES 'utf8'");
 }
Esempio n. 6
0
 public static function connect($host, $user, $password, $database)
 {
     if (!isset(self::$connection)) {
         self::$connection = @new PDO("mysql:host={$host};dbname={$database}", $user, $password, self::$settings);
         return true;
     }
     return false;
 }
Esempio n. 7
0
 public function connect()
 {
     if (!isset(self::$connection)) {
         self::$connection = new mysqli('localhost', "root", "", "gotit");
     }
     if (self::$connection === false) {
         return false;
     }
     return self::$connection;
 }
Esempio n. 8
0
 /**
  * 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('../config/config.ini');
         self::$connection = new mysqli($config['host'], $config['username'], $config['password'], $config['dbname']);
     }
     if (self::$connection === false) {
         return false;
     }
     return self::$connection;
 }
Esempio n. 9
0
 public function connect()
 {
     if (!isset(self::$connection)) {
         $login = $this->readLogin("../../config.json");
         self::$connection = new mysqli($login["hostname"], $login["username"], $login["password"], $login["db"]);
     }
     if (self::$connection->connect_errno) {
         echo "Failed to connect to MySQL: " . self::$connection->connect_error;
         return false;
     }
     return self::$connection;
 }
Esempio n. 10
0
 /**
  * Connect to database.
  */
 public static function connect()
 {
     self::$connection = mysql_connect(DB_SERVER, DB_USERNAME, DB_PASSWORD);
     if (!self::$connection) {
         trigger_error('Can\'t connect to database.');
         return false;
     } else {
         mysql_select_db(DB_DATABASE);
         mysql_query("SET CHARACTER SET " . MYSQL_CHARSET);
         return true;
     }
 }
Esempio n. 11
0
 /**
  * Connect to the database
  * 
  * @return bool false on failure / mysqli MySQLi object instance on success
  */
 public function connect()
 {
     // Try and connect to the database
     if (!isset(self::$connection)) {
         self::$connection = new mysqli(global_mysql_server, global_mysql_user, global_mysql_password, global_mysql_database);
     }
     // If connection was not successful, handle the error
     if (self::$connection === false) {
         // Handle error - notify administrator, log to a file, show an error screen, etc.
         return false;
     }
     return self::$connection;
 }
Esempio n. 12
0
 public function connect()
 {
     if (!isset(self::$connection)) {
         self::$connection = new mysqli(\DbConfig::HOST, \DbConfig::USER_NAME, \DbConfig::USER_PASSWORD, \DbConfig::DB_NAME);
     }
     //If connection was not success, handle the error
     if (!self::$connection) {
         // Handle error - notify administrator, log to a file, show an error screen, etc.
         return false;
     }
     self::$connection->autocommit(false);
     return self::$connection;
 }
Esempio n. 13
0
 /**
  * Connect to the database
  * 
  * @return bool false on failure / mysqli MySQLi object instance on success
  */
 public function connect()
 {
     // Try and connect to the database
     if (!isset(self::$connection)) {
         // Load configuration as an array. Use the actual location of your configuration file
         self::$connection = new mysqli('localhost', 'root', 'root', 'servicioslegales');
     }
     // If connection was not successful, handle the error
     if (self::$connection === false) {
         // Handle error - notify administrator, log to a file, show an error screen, etc.
         return false;
     }
     return self::$connection;
 }
 /**
  * Connect to the database
  * 
  * @return bool false on failure / mysqli MySQLi object instance on success
  */
 public function connect()
 {
     // Try and connect to the database
     if (!isset(self::$connection)) {
         // Load configuration as an array. Use the actual location of your configuration file
         // Put the configuration file outside of the document root
         self::$connection = new mysqli(DB_SERVER, DB_USER, DB_PASSWORD, DB_NAME);
     }
     // If connection was not successful, handle the error
     if (self::$connection === false) {
         // Handle error - notify administrator, log to a file, show an error screen, etc.
         return false;
     }
     return self::$connection;
 }
Esempio n. 15
0
 public function connect()
 {
     // Try and connect to the database, if a connection has not been established yet
     if (!isset(self::$connection)) {
         // Load configuration
         self::$connection = mysqli_connect(host, user, pass, dbname) or die("no connection");
         mysqli_select_db(self::$connection, 'moviefy');
     }
     // If connection was not successful, handle the error
     if (self::$connection === false) {
         //Handle Error - notify admin
         return mysqli_connect_error($connection);
     }
     return self::$connection;
 }
 /**
  * Connect to the database
  *
  * @return bool false on failure / mysqli MySQLi object instance on success
  */
 public function connect()
 {
     // Try and connect to the database
     if (!isset(self::$connection)) {
         // Load configuration as an array. Use the actual location of your configuration file
         $config = parse_ini_file('../config/config.ini');
         self::$connection = new mysqli('localhost', $config['username'], $config['password'], $config['dbname']);
     }
     // If connection was not successful, handle the error
     if (self::$connection === false) {
         // Handle error - notify administrator, log to a file, show an error screen, etc.
         return false;
     }
     return self::$connection;
 }
Esempio n. 17
0
File: db.php Progetto: ucantseeme/p1
 public static function connect()
 {
     //try and connect to database
     if (!isset(self::$connection)) {
         //load configuration as an array
         global $config;
         self::$connection = new mysqli($config['host'], $config['username'], $config['password'], $config['db']);
     }
     //if connection was not successful, handle the error
     if (self::$connection === false) {
         // Handle error - notify administrator, log to a file, show an error screen, etc.
         return false;
     }
     return self::$connection;
 }
Esempio n. 18
0
 /**
  * Connect to the database
  * 
  * @return bool false on failure / mysqli MySQLi object instance on success
  */
 public function connect()
 {
     // Try and connect to the database
     if (!isset(self::$connection)) {
         // get database settings
         $root = realpath($_SERVER["DOCUMENT_ROOT"]);
         include "{$root}/dbsettings/dbsettings.php";
         self::$connection = new mysqli($sql_details['host'], $sql_details['user'], $sql_details['pass'], $sql_details['db']);
     }
     // If connection was not successful, handle the error
     if (self::$connection === false) {
         // Handle error - notify administrator, log to a file, show an error screen, etc.
         return false;
     }
     return self::$connection;
 }
Esempio n. 19
0
 public static function pdoConnect()
 {
     global $server;
     global $username;
     global $password;
     global $database;
     try {
         if (!self::$hasConnection) {
             self::$connection = new PDO("mysql:host={$server};dbname=" . $database, $username, $password);
             self::$connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
             self::$hasConnection = true;
         }
         return self::$connection;
     } catch (PDOException $e) {
         echo "Connection failed: " . $e->getMessage();
     }
 }
Esempio n. 20
0
 /**
  * Connect to the database
  * 
  * @return bool false on failure / mysqli MySQLi object instance on success
  */
 public static function connect()
 {
     // Try and connect to the database
     if (!isset(self::$connection)) {
         echo "New connection<br>";
         // Load configuration as an array. Use the actual location of your configuration file
         //$config = parse_ini_file('./config.ini');
         //self::$connection = new mysqli('localhost',$config['username'],$config['password'],$config['dbname']);
         self::$connection = new mysqli("localhost", "kano", "kano", "kano");
     }
     // If connection was not successful, handle the error
     if (self::$connection === false) {
         // Handle error - notify administrator, log to a file, show an error screen, etc.
         die("Connection failed: " . $connection->connect_error);
         return false;
     }
     return self::$connection;
 }
Esempio n. 21
0
 /**
  * Connect to the database
  * 
  * @return bool false on failure / mysqli MySQLi object instance on success
  */
 public function connect()
 {
     if (!isset(self::$connection)) {
         if (session_status() == PHP_SESSION_NONE) {
             session_start();
         }
         if (!isset($_SESSION['host']) or !isset($_SESSION['username']) or !isset($_SESSION['password']) or !isset($_SESSION['dbname'])) {
             die("db.class: can't get database connection info from session");
         } else {
             self::$connection = new mysqli($_SESSION['host'], $_SESSION['username'], $_SESSION['password'], $_SESSION['dbname']);
         }
     }
     if (self::$connection === false) {
         die('"db.class: Unable to connect to database');
         return false;
     }
     return self::$connection;
 }
Esempio n. 22
0
 public function connect()
 {
     $_host = DATABASE_HOSTNAME;
     $_username = DATABASE_USERNAME;
     $_password = DATABASE_PASSWORD;
     $_database = DATABASE_DATABASE;
     // Try and connect to the database
     if (!isset(self::$connection)) {
         // Load configuration as an array. Use the actual location of your configuration file
         // Put the configuration file outside of the document root
         self::$connection = new mysqli($_host, $_username, $_password, $_database);
     }
     // If connection was not successful, handle the error
     if (self::$connection === false) {
         // Handle error - notify administrator, log to a file, show an error screen, etc.
         return false;
     }
     return self::$connection;
 }
Esempio n. 23
0
File: Test.php Progetto: hisaboh/w2t
 public static function __shutdown__()
 {
     if (self::$ftmp !== null && is_dir(self::ftpath())) {
         foreach (File::dirs(self::ftpath()) as $dir) {
             File::rm($dir);
         }
     }
     if (!empty(self::$TMP_DB)) {
         foreach (self::$TMP_DB as $db => $table) {
             $dobj = Db::connection($db);
             foreach ($table as $name => $value) {
                 $dobj->drop_table($name);
                 $dobj->commit();
             }
         }
     }
 }
Esempio n. 24
0
 public function close()
 {
     self::$connection = null;
 }
Esempio n. 25
0
 public static function connect($db_host, $db_name, $username, $password)
 {
     if (!isset(self::$connection)) {
         self::$connection = new PDO('mysql:host=' . $db_host . ';dbname=' . $db_name, $username, $password, self::$config);
     }
 }
 public function testPassGetter()
 {
     $this->assertInstanceOf('MongoCollection', Db::connection()->test);
 }
Esempio n. 27
0
File: Dao.php Progetto: hisaboh/w2t
 protected final function get_connection()
 {
     if (!isset(self::$CONNECTION[$this->_class_])) {
         self::$CONNECTION[$this->_class_] = Db::connection($this->_database_);
     }
     if (empty($this->_table_)) {
         $this->_table_ = strtolower($this->_class_[0]);
         for ($i = 1; $i < strlen($this->_class_); $i++) {
             $this->_table_ .= ctype_lower($this->_class_[$i]) ? $this->_class_[$i] : "_" . strtolower($this->_class_[$i]);
         }
     }
     $this->_table_ = $this->set_table_name($this->_table_);
     $dbtype = $this->connection()->type();
     $this->add_modules(new $dbtype());
 }