/** * Get populatd PDO. * * @return PDO */ protected function getPopulatedDbConnection() { $factory = new T_Pdo_Connection('sqlite::memory:'); $pdo = $factory->connect(); $pdo->exec($this->getCreateTableSql()); return $pdo; }
function testConnectionFailureResultsInException() { try { $factory = new T_Pdo_Connection('notadsn'); $factory->connect(); $this->fail(); } catch (T_Exception_Db $e) { $this->assertTrue(strlen($e->getMessage()) > 0); } }
/** * Get connection. * * @return PDO * @throws T_Exception_Db on connection failure */ function connect($context = null) { $init = is_null($this->conn); $conn = parent::connect($context); if ($init) { $conn->exec("SET CLIENT_ENCODING TO 'utf8'"); $conn->exec("SET TIME ZONE '+0:00'"); } return $conn; }
/** * Get connection. * * @return PDO * @throws T_Exception_Db on connection failure */ function connect($context = null) { $init = is_null($this->conn); $conn = parent::connect($context); if ($init) { $conn->exec("SET CHARACTER SET utf8, time_zone='+0:00'"); // The connection character set must be consistent with the lib (utf8). // MySQL also supports the concept of timezones, and although they do not // have a affect on stored values, they do affect the value of NOW() // and extraction of UNIX_TIMESTAMPS(__). All data passed to the db should // be in UTC (i.e. GMT). // // the most efficient way of doing this is probably to use a last // argument to the parent constructor of // array(PDO::MYSQL_ATTR_INIT_COMMAND => $sql) // However, a PHP5.3 bug means this constant is not always defined, so for // compatibility we issue the query separately. } return $conn; }