<?php namespace Laravel\Database\Connectors; use PDO; class SQLite extends Connector { /** * Establish a PDO database connection. * 建立 PDO 数据库连接。 * @param array $config * @return PDO */ public function connect($config) { $options = $this->options($config); // SQLite provides supported for "in-memory" databases, which exist only for the // lifetime of the request. Any given in-memory database may only have one PDO // connection open to it at a time. These are usually for testing. // SQLite 为“内存中”数据库提供支持,这些数据库仅在请求的生命周期内存在。 // 任何给定的内存数据库一次只能打开一个 PDO 连接。 这些通常用于测试。 if ($config['database'] == ':memory:') { return new PDO('sqlite::memory:', null, null, $options); } // SQLite databases will be created automatically if they do not exist, so we // will not check for the existence of the database file before establishing // the PDO connection to the database. // 如果 SQLite 数据库不存在,则会自动创建,因此在建立与数据库的 PDO 连接之前,我们不会检查数据库文件是否存在。 $path = path('storage').'database'.DS.$config['database'].'.sqlite'; return new PDO('sqlite:'.$path, null, null, $options); } }
github地址: https://github.com/liu-shilong/laravel3-scr