Ground Sunlight

Windowsで作る - PHPプログラミングの開発環境

ユーザ用ツール

サイト用ツール


apricot:usage:ja:database

差分

このページの2つのバージョン間の差分を表示します。

この比較画面にリンクする

両方とも前のリビジョン 前のリビジョン
次のリビジョン
前のリビジョン
apricot:usage:ja:database [2020/08/20 21:27]
y2sunlight [SQLファイル]
apricot:usage:ja:database [2020/09/17 15:05] (現在)
y2sunlight [Idiormの設定ファイル]
行 15: 行 15:
   * [[apricot:usage:ja:middleware|Apricot ミドルウェア]]   * [[apricot:usage:ja:middleware|Apricot ミドルウェア]]
   * [[apricot:usage:ja:controller|Apricot コントローラ]]   * [[apricot:usage:ja:controller|Apricot コントローラ]]
 +  * [[apricot:usage:ja:validation|Apricot バリデーション]]
 +  * [[apricot:usage:ja:provider|Apricot サービスプロバイダー]]
 +  * [[apricot:usage:ja:authentication|Apricot ユーザ認証]]
   * [[apricot:usage:ja:utility|Apricot ユーティリティ]]   * [[apricot:usage:ja:utility|Apricot ユーティリティ]]
  
行 23: 行 26:
 Apricotでは、ORマッパーに[[basic-library:idiorm:1.5|Idiorm]]を使用します。詳しい使い方やメソッドについてはIdiormの[[https://idiorm.readthedocs.io/en/latest/|マニュアル]]を参照して下さい。 Apricotでは、ORマッパーに[[basic-library:idiorm:1.5|Idiorm]]を使用します。詳しい使い方やメソッドについてはIdiormの[[https://idiorm.readthedocs.io/en/latest/|マニュアル]]を参照して下さい。
  
-Idiormの典型的な使用例を示します:+Idiorm の典型的な使用例を示します:
  
 <code php> <code php>
行 52: 行 55:
     [     [
         'sqlite' => [         'sqlite' => [
-            'db_file' => var_dir('db/apricot.sqlite'), 
             'connection_string' => 'sqlite:'.var_dir('db/apricot.sqlite'),             'connection_string' => 'sqlite:'.var_dir('db/apricot.sqlite'),
 +            'db_file' => var_dir('db/apricot.sqlite'),
         ],         ],
         'mysql' => [         'mysql' => [
行 59: 行 62:
             'username' => 'apricot',             'username' => 'apricot',
             'password' => 'password',             'password' => 'password',
 +            'driver_options' => [PDO::MYSQL_ATTR_INIT_COMMAND => 'set names utf8'],
             'check_tables' => 'show tables like \'user\'',             'check_tables' => 'show tables like \'user\'',
 +            'initial_statements'=> [
 +                'set names utf8',
 +            ],
         ],         ],
     ],     ],
行 101: 行 108:
   * username --- データベースのユーザ名   * username --- データベースのユーザ名
   * password --- ユーザのパスワード   * password --- ユーザのパスワード
 +  * driver_options --- データベースドライバー毎のオプション
   * check_tables --- アプリケーションで使用するテーブルの存在を確認するSQL文   * check_tables --- アプリケーションで使用するテーブルの存在を確認するSQL文
 +  * initial_statements --- 接続直後に実行する初期化SQL文
  
-''connection_string'' は必須です。''db_file'' は SQLite のようなファイル共有型のデータベースの場合に必要で、''username'' と ''password'' は MySQL のようなクライアント-サーバ型のデータベースの場合に必要になります。+''connection_string'' は必須です。''db_file'' は SQLite のようなファイル共有型のデータベースの場合に必要で、''username'' と ''password'' は MySQL のようなクライアント-サーバ型のデータベースの場合に必要になります。''connection_string'' と ''driver_options'' についてはを PHPの[[https://www.php.net/manual/en/pdo.drivers.php|PDO driver-specific documentation]] 参照して下さい
  
 > 接続設定及び接続文字列の詳細は以下を参照して下さい:\\ https://idiorm.readthedocs.io/en/latest/configuration.html#id1 > 接続設定及び接続文字列の詳細は以下を参照して下さい:\\ https://idiorm.readthedocs.io/en/latest/configuration.html#id1
  
 ''check_tables'' はオプションで、アプリケーションで使用するテーブルの存在を調べるSQLクエリ文を設定します。詳しくは次項の[[#テーブルの作成|Idiormのセットアップ]]を参照して下さい。 ''check_tables'' はオプションで、アプリケーションで使用するテーブルの存在を調べるSQLクエリ文を設定します。詳しくは次項の[[#テーブルの作成|Idiormのセットアップ]]を参照して下さい。
 +
 +''initial_statements'' はオプションで、データベースとの接続直後に実行するSQL文を設定します。このSQL文は複数指定することができます。
  
 === initial_data === === initial_data ===
行 243: 行 254:
 ''file_get_sql()'' 関数 はアプリケーションの中で任意のSQLファイルに使用できます。但し、SQLファイルの保存先は ''create.sql'' ファイルと同じ場所を推奨します。 ''file_get_sql()'' 関数 はアプリケーションの中で任意のSQLファイルに使用できます。但し、SQLファイルの保存先は ''create.sql'' ファイルと同じ場所を推奨します。
  
-Idiormのセットアップコードでは、''file_get_sql()'' 関数を使用して以下のように ''create.sql'' を読み込んでSQL文を実行います。+Idiormのセットアップコードでは、''file_get_sql()'' 関数を使用して以下のように ''create.sql'' を読み込んでSQL文を実行しています。
  
 <code php> <code php>
行 256: 行 267:
 </code> </code>
  
 +\\
 +
 +=== SQLファイルの形式について ===
 +
 +以下に、Apricotのスケルトンで提供されているSQLite用のSQLファイルを示します。
 +
 +{{fa>folder-open-o}} ** /your-project/assets/sql/sqlite **
 +<code sql create.sql>
 +/*
 + * User Table
 + */
 +create table if not exists user
 +(
 +    id integer primary key autoincrement,
 +    account text unique not null,
 +    password text not null,
 +    email text,
 +    note text,
 +    remember_token text,
 +    created_at text not null,
 +    updated_at text not null,
 +    version_no integer default 0 not null
 +);
 +</code>
 +
 +  * SQLの文法及び使用できる関数などは使用しているデーターベース( 上例では SQLite )に依存します。
 +  * 行コメント( ''<nowiki>-- Comment</nowiki>'' )とブロックコメント( ''/* Comment */'' )の両方が使用できます。
 +  * 文はセミコロン( '';'' )で区切って複数入力できます。
 +  * 連続する空白( ''TAB'', ''Space'', ''改行文字'' )は1つの空白と同じにみなされます。
  
 \\ \\
  
apricot/usage/ja/database.1597926422.txt.gz · 最終更新: 2020/08/20 21:27 by y2sunlight