public static function setConnection($config = []) { if (static::$conn === null) { static::$conn = \Doctrine\DBAL\DriverManager::getConnection($config, new \Doctrine\DBAL\Configuration()); } return static::$conn; }
public static function setUpBeforeClass() { $configDir = __DIR__ . '/../../../config'; static::$structure = Structure::createFromYaml($configDir . '/structure.yml'); static::$conn = (require_once $configDir . '/config.php'); static::$mf = new ManagerFactory(static::$conn, static::$structure, true); }
public function __destruct() { if (!is_null(static::$conn)) { static::$conn->close(); static::$conn = null; } }
/** * @todo: Нужно переписать, что бы в качестве PDO можно было передать что-то другое - DI * @return mixed */ protected function connect() { if (null === static::$conn) { static::$conn = new \PDO('mysql:host=' . $this->options['host'] . ';' . 'port=' . $this->options['port'] . ';', $this->options['user'], $this->options['password']); } return static::$conn; }
static function connect() { if (!static::$conn) { static::$conn = mysqli_connect('localhost', getenv('MYSQL_USER'), getenv('MYSQL_PASSWORD')); mysqli_select_db(static::$conn, getenv('MYSQL_DB')); } return static::$conn; }
static function getconn() { if (!static::$conn) { static::$conn = new mysqli(static::$servername, static::$username, static::$password, static::$dbname); if (static::$conn->connect_error) { die("Connection failed: "); } } return static::$conn; }
public static function conn() { if (static::$conn === null) { static::$config = new \Doctrine\DBAL\Configuration(); $connectionParams = array('host' => Config::get('db_host'), 'driver' => 'pdo_mysql', 'user' => Config::get('db_login'), 'password' => Config::get('db_password'), 'dbname' => Config::get('db_name'), 'charset' => 'utf8'); static::$conn = \Doctrine\DBAL\DriverManager::getConnection($connectionParams, static::$config); static::$conn->getDatabasePlatform()->registerDoctrineTypeMapping('enum', 'string'); } return static::$conn; }
/** * @return \Doctrine\DBAL\Connection * @throws \Doctrine\DBAL\DBALException * @throws \Exception */ public static function getConn() { $doctrineConfig = new Configuration(); if (!empty(self::$conf)) { static::$conn = DriverManager::getConnection(self::$conf, $doctrineConfig); } else { throw new \Exception('Configuration problems'); } return static::$conn; }
/** * @return \Doctrine\DBAL\Connection * @throws \Doctrine\DBAL\DBALException * @throws \Exception */ public static function getConn() { if (null === static::$conn) { $doctrineConfig = new Configuration(); $yaml = new Parser(); $config = $yaml->parse(file_get_contents('pabtest-config.yml')); if (!empty($config['db'])) { static::$conn = DriverManager::getConnection($config['db'], $doctrineConfig); } else { throw new \Exception('Configuration problems'); } } return static::$conn; }
/** * Get the only object available */ public static function getInstance() { //create an object of DBConnection if (null == static::$conn) { try { static::$conn = new PDO(sprintf("mysql:host=%s;dbname=%s", static::$HOSTNAME, static::$DATABASE), static::$USERNAME, static::$PASSWORD); //enable to throw error,otherwise can't throw error static::$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } catch (PDOException $e) { print "Error!: " . $e->getMessage() . "<br/>"; die; } } return static::$conn; }
/** * Create database tables required for testing. * * @return array array of test data created */ public static function setUp() { //Load environment variables $dotenv = new \Dotenv\Dotenv(__DIR__ . '/../../'); if (!getenv('APP_ENV')) { $dotenv->load(); } //Create connection and execute schema static::$conn = new Connection(); Schema::createSchema(); //Add test data to user table if not exist or no errors returned $user = User::firstOrCreate(['username' => 'test-root', 'password' => hash('SHA256', 'test-root')]); $emojiData = ['name' => 'Happy Face', 'char' => ':)', 'category' => 'Happy']; //Build keywords array and create users emojis $keywords = ['happy', 'face', 'emotion']; $emoji = $user->emojis()->firstOrCreate($emojiData); //Add keywords to keywords table $keyId = []; foreach ($keywords as $keyword) { $key = $emoji->keywords()->firstOrCreate(['name' => $keyword]); $keyId[] = $key->id; } return ['userId' => $user->id, 'emojiId' => $emoji->id, 'keywordsId' => $keyId]; }
/** * Initializes static fields, including a call to Columns() to get field types. */ protected static function Init() { if (is_null(static::$table)) { static::$table = strtolower(get_called_class()); } if (is_null(static::$conn) && isset($GLOBALS['conn'])) { static::$conn = $GLOBALS['conn']; } if (is_null(static::$cache) && isset($GLOBALS['cache'])) { static::$cache = $GLOBALS['cache']; } if (is_null(static::$columns)) { static::$columns = static::Columns(); } }
public function __construct($conn) { $this->transactionID = rand(); static::$conn = $conn; }
public function __construct($url) { if (is_null(static::$config) && isset($GLOBALS['config'])) { static::$config = $GLOBALS['config']; } if (is_null(static::$conn) && isset($GLOBALS['conn'])) { static::$conn = $GLOBALS['conn']; } if (is_null(static::$cache) && isset($GLOBALS['cache'])) { static::$cache = $GLOBALS['cache']; } if (is_null(static::$session) && isset($GLOBALS['session'])) { static::$session = $GLOBALS['session']; } $this->url = $url; $this->Init(); }
public static function configureDB($dsn, $username, $password) { static::$conn = DB::getConnection($dsn, $username, $password); }
public static function init() { static::$conn = new PDO(Config::$dbName); static::$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); static::createTables(); }
/** * Set ActiveRecord default connection * * @param Connection $conn */ public static function setConnection(Connection $conn) { static::$conn = $conn; }
public function __construct() { if (is_null(static::$config) && isset($GLOBALS['config'])) { static::$config = $GLOBALS['config']; } if (is_null(static::$conn) && isset($GLOBALS['conn'])) { static::$conn = $GLOBALS['conn']; } if (is_null(static::$cache) && isset($GLOBALS['cache'])) { static::$cache = $GLOBALS['cache']; } $this->time['start'] = GetMicroTime(); $this->Limits(); }