private final function __construct() { try { $a = Application::getAppInfo(); self::$connection = new PDO("mysql:host=" . $a->GetDBHost() . ";dbname=" . $a->GetDBName(), $a->GetDBUser(), $a->GetDBPass()); } catch (PDOException $e) { throw new Exception("Impossible to establish connection to DB"); } }
/** consider making private (which forces you to use executeSQLSelect() and executeSQLCommand() */ public static function getConnection() { if (self::$connection === null) { self::$connection = new PDO('mysql:host=localhost;port=3307;dbname=gtlol', 'gtloladmin', 'poppy'); return new PDO('mysql:host=localhost;port=3307;dbname=gtlol', 'gtloladmin', 'poppy'); } else { return self::$connection; } }
/** * Returns a PDO object for a connection to the database * * @return PDO * */ public static function getConnection() { // Credentials for the DB require UTIL_DB_CREDS; // Only complete if the connection does not exist if (self::$connection === null) { try { // Create the DB connection self::$connection = new PDO($dsn, $user, $pass); # Fires exceptions. Use try/catch with this self::$connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } catch (PDOException $e) { echo $e->getMessage(); die; } } return self::$connection; }