LoginSignup
7
6

More than 5 years have passed since last update.

[PHP] laravelでsqliteを利用

Last updated at Posted at 2016-10-11

laravelインストール記事

  1. [PHP] laravelを利用したので、インストールメモ
  2. [PHP] laravelでsqliteを利用
  3. [PHP] laravelでseederを利用

sqliteはインストールしておく

# yum install sqlite sqlite-devel
$ cd {プロジェクトディレクトリ}
$ sqlite3 database/development.sqlite3
sqlite> .tables     <- 0byteのファイルができます。 (touch database/development.sqlite3 でも可)
sqlite> .q

.gitignoreにファイルをsqliteファイルを追記

.gitignore
/database/*.sqlite3

config

.env
#DB_CONNECTION=mysql
#DB_HOST=127.0.0.1
#DB_PORT=3306
#DB_DATABASE=homestead
#DB_USERNAME=homestead
#DB_PASSWORD=secret
DB_CONNECTION=sqlite
DB_DATABASE=database/development.sqlite3

tinkerを使って変更内容を確認 (tinkerとは、laravelのconsoleです。)

$ php artisan tinker
Psy Shell v0.7.2 (PHP 5.6.24 — cli) by Justin Hileman
>>> env('DB_CONNECTION')
=> "sqlite"
>>> env('DB_DATABASE')
=> "database/development.sqlite3"

migration

準備されているusers, password_resetsテーブルを作成する。

$ ls database/migrations/
2014_10_12_000000_create_users_table.php  2014_10_12_100000_create_password_resets_table.php
$ php artisan migrate
Migration table created successfully.
Migrated: 2014_10_12_000000_create_users_table
Migrated: 2014_10_12_100000_create_password_resets_table
$ sqlite3 database/development.sqlite3
SQLite version 3.6.20
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> .tables
migrations       password_resets  users

テーブル作成まで。

7
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
6