sqlite.php 1.0 KB

1234567891011121314151617181920212223242526272829303132
  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. Generally, these databases are used for
  15. // testing and development purposes, not in production scenarios.
  16. if ($config['database'] == ':memory:')
  17. {
  18. return new PDO('sqlite::memory:', null, null, $options);
  19. }
  20. // SQLite databases will be created automatically if they do not exist, so we
  21. // will not check for the existence of the database file before establishing
  22. // the PDO connection to the database.
  23. $path = $GLOBALS['STORAGE_PATH'].'database'.DS.$config['database'].'.sqlite';
  24. return new PDO('sqlite:'.$path, null, null, $options);
  25. }
  26. }