sqlite.php 738 B

12345678910111213141516171819202122232425262728293031
  1. <?php namespace Laravel\Database\Connector;
  2. use Laravel\Database\Connector;
  3. class SQLite extends Connector {
  4. /**
  5. * Establish a PDO database connection.
  6. *
  7. * @param array $config
  8. * @return PDO
  9. */
  10. public function connect($config)
  11. {
  12. if ($config['database'] == ':memory:')
  13. {
  14. return new \PDO('sqlite::memory:', null, null, $this->options);
  15. }
  16. elseif (file_exists($path = DATABASE_PATH.$config['database'].'.sqlite'))
  17. {
  18. return new \PDO('sqlite:'.$path, null, null, $this->options);
  19. }
  20. elseif (file_exists($config['database']))
  21. {
  22. return new \PDO('sqlite:'.$config['database'], null, null, $this->options);
  23. }
  24. throw new \Exception("SQLite database [".$config['database']."] could not be found.");
  25. }
  26. }