合规国际互联网加速 OSASE为企业客户提供高速稳定SD-WAN国际加速解决方案。 广告
### 数据库 **依赖包** 包括数据库、表单和国际化支持 > composer.json ```json "require": { "php": "^5.6 || ^7.0", "zendframework/zend-component-installer": "^1.0 || ^0.7 || ^1.0.0-dev@dev", "zendframework/zend-mvc": "^3.0.1", "zfcampus/zf-development-mode": "^3.0", "zendframework/zend-db": "^2.8", "zendframework/zend-form": "^2.9", "zendframework/zend-i18n": "^2.7" }, ``` 更新 ``` composer update ``` **创建数据库** 专辑列表 SQL 文件 > data/schema.sql ```sql CREATE TABLE album (id INTEGER PRIMARY KEY AUTOINCREMENT, artist varchar(100) NOT NULL, title varchar(100) NOT NULL); INSERT INTO album (artist, title) VALUES ('The Military Wives', 'In My Dreams'); INSERT INTO album (artist, title) VALUES ('Adele', '21'); INSERT INTO album (artist, title) VALUES ('Bruce Springsteen', 'Wrecking Ball (Deluxe)'); INSERT INTO album (artist, title) VALUES ('Lana Del Rey', 'Born To Die'); INSERT INTO album (artist, title) VALUES ('Gotye', 'Making Mirrors'); ``` 使用 SQLite 命令行 ```sqlite sqlite3 data/zftutorial.db < data/schema.sql ``` 或者使用 PHP 创建 > data/load_db.php ```php <?php $db = new PDO('sqlite:' . realpath(__DIR__) . '/zftutorial.db'); $fh = fopen(__DIR__ . '/schema.sql', 'r'); while ($line = fread($fh, 4096)) { $db->exec($line); } fclose($fh); ``` 执行 ``` php data/load_db.php ``` **数据库配置** 驱动类型和数据源名称 > config/autoload/global.php ```php return [ 'db' => [ 'driver' => 'Pdo', 'dsn' => sprintf('sqlite:%s/data/zftutorial.db', realpath(getcwd())), ], ]; ```