sqlite.php 941 B

12345678910111213141516171819202122232425262728293031
  1. <?php namespace Laravel\Database\Connectors; use PDO;
  2. class SQLite extends Connector {
  3. /**
  4. * Establish a PDO database connection.
  5. *
  6. * @param array $config
  7. * @return PDO
  8. */
  9. public function connect($config)
  10. {
  11. $options = $this->options($config);
  12. // SQLite provides supported for "in-memory" databases, which exist only for the
  13. // lifetime of the request. Any given in-memory database may only have one PDO
  14. // connection open to it at a time. These are usually for testing.
  15. if ($config['database'] == ':memory:')
  16. {
  17. return new PDO('sqlite::memory:', null, null, $options);
  18. }
  19. // SQLite databases will be created automatically if they do not exist, so we
  20. // will not check for the existence of the database file before establishing
  21. // the PDO connection to the database.
  22. $path = path('storage').'database'.DS.$config['database'].'.sqlite';
  23. return new PDO('sqlite:'.$path, null, null, $options);
  24. }
  25. }