public static function create($table, Dsn $dsn = null)
 {
     if (!$dsn) {
         $dsn = new Dsn(Config::driver(), Config::dsn());
     }
     $adapter = TableAdapterFactory::instance()->createTableAdapter($dsn, $table);
     return new TableGateway($adapter);
 }
Example #2
0
 /**
  * {@inheritdoc}
  */
 public function connect()
 {
     if ($this->config->dsn === null && $this->config->db !== null) {
         trigger_error('Config::$db is deprecated, see Config::$dsn.', E_USER_DEPRECATED);
         $this->config->dsn("mysql:dbname={$this->config->db};host={$this->config->host}");
     }
     try {
         $this->pdo = new \PDO($this->config->dsn, $this->config->user, $this->config->pass);
         $this->pdo->exec('SET NAMES ' . $this->config->encoding);
         foreach ($this->config->attributes as $name => $value) {
             $this->pdo->setAttribute($name, $value);
         }
         $sth = $this->pdo->query('SELECT DATABASE() FROM DUAL');
         $database = $sth->fetch();
         $this->database = end($database);
         $this->version = (string) $this->pdo->getAttribute(\PDO::ATTR_SERVER_VERSION);
     } catch (\PDOException $e) {
         throw new Exception('Connecting to database failed with message: ' . $e->getMessage());
     }
 }