プログラミング

sqlite3 & php class Library 応用編

SQLite3 PHP Class Library を利用して .help のデータベースを作ってみました。

sqlite3 を操作するにはGUI環境のツールもいくつかるようですが、やはり基本コマンドラインで作業する場合が多いと思います。
コマンドラインは手軽ですが、データ更新等々はSQLを発行する必要がありますね。 ここでは数あるツールもいいのですが、Php Class ライブラリーを拡張しツールを兼ねてアプリケーションとしてクラスを継承してつかえるような拡張ライブラリーをつくってみました。
今回のサンプルはすべての機能を利用していませんが、まず手始めに紹介します。

作成したphp標準のクラスライブラリーの独自関数の一部です。

functions.php に ショートコードためのコードを追加

CSS (おまけ)

.help データベースのサンプル表示

.backup ?DB? FILE
Backup DB (default "main") to FILE
DBを指定したファイル名でバックアップ。
バックアップするDBを指定しなかった場合はmain
のDBをバックアップする。
.bail ON|OFF
Stop after hitting an error.  Default OFF
エラーがあった場合に実行を止めるか否か。
デフォルトはオフ。
.databases
List names and files of attached databases
DBの一覧を表示。
.dump ?TABLE? ...
Dump the database in an SQL text format
 If TABLE specified, only dump tables matching
 LIKE pattern TABLE
テキスト形式でDBをダンプ。
テーブルを指定した場合は
それにマッチしたものだけをダンプ。
.echo ON|OFF
Turn command echo on or off
コマンドエコーのオン/オフ。
.exit
Exit this program
このプログラムを終了。
.explain ?ON|OFF?
Turn output mode suitable for EXPLAIN on or off.
 With no args, it turns EXPLAIN on.
EXPLAINに合った出力モードのオン/オフ。
引数がない場合はオン。
.header(s) ON|OFF
Turn display of headers on or off
ヘッダー表示のオン/オフ。
.help
Show this message
ヘルプを表示。
.import FILE TABLE
Import data from FILE into TABLE
FILEのデータをTABLEにインポート。
.indices ?TABLE?
Show names of all indices
 If TABLE specified, only show indices for tables
 matching LIKE pattern TABLE.
TABLEに関するすべてのインデックス名を表示。
テーブルを指定した場合はそれにマッチした
テーブルのインデックス名を表示。
.log FILE|off
Turn logging on or off.  FILE can be stderr/stdout
ログのオン/オフ。
.mode MODE ?TABLE?
Set output mode where MODE is one of:
    csv      Comma-separated values
    column   Left-aligned columns.  (See .width)
    html     HTML <table> code
    insert   SQL insert statements for TABLE
    line     One value per line
    list     Values delimited by .separator string
    tabs     Tab-separated values
    tcl      TCL list elements
出力モードの切換え。 
 csv    カンマ区切りで出力 
 column    左寄せのカラム出力 
 html    HTMLタブで出力 
 insert    SQLのINSERT文で出力 
 line    1行で出力 
 list    区切り文字でカラムを区切り1行で出力 
 tabs    タブ区切りで出力 
 tcl    TCLのlist形式で出力 
.nullvalue STRING
Use STRING in place of NULL values
値がNULLのとき、代わりにSTRINGを出力。
.output FILENAME
Send output to FILENAME
FILENAMEに出力を送る。
.output stdout
Send output to the screen
スクリーンに出力を送る。
.prompt MAIN CONTINUE
Replace the standard prompts
プロンプトの表示を変更する。
.quit
Exit this program
このプログラムを終了。
.read FILENAME
Execute SQL in FILENAME
外部SQLの実行。
.restore ?DB? FILE
Restore content of DB (default "main") from FILE
FILEからDBの内容を復元する(デフォルトは "main")
.schema ?TABLE?
Show the CREATE statements
 If TABLE specified, only show tables matching
 LIKE pattern TABLE.
スキーマの確認。
TABLEを指定した場合、パターンにマッチした
TABLEのスキーマを確認。
.separator STRING
Change separator used by output mode and .import
区切り文字を変更する。.importにも影響。
.show
Show the current values for various settings
現在の設定を表示。
.stats ON|OFF
Turn stats on or off
統計のオン/オフ。
.tables ?TABLE?
List names of tables
 If TABLE specified, only list tables matching
 LIKE pattern TABLE.
テーブルのリスト表示。
TABLEを指定した場合は、パターンに
マッチしたリストを表示。
.timeout MS
Try opening locked tables for MS milliseconds
ロックされたテーブルを開くのにMSミリ秒待つ。
.vfsname ?AUX?
Print the name of the VFS stack
VFSスタックの名前を出力。
.width NUM1 NUM2 ...
Set column widths for "column" mode
カラムの横幅を指定。
.timer ON|OFF
Turn the CPU timer measurement on or off
CPU時間計測のオン/オフ。

最近の記事

  1. wordpres5をubuntu nginxにインストール
  2. ubuntu 20.04 nginx php mysql Webサーバー環境整備
  3. Ubuntu nginx SSL
  4. EC-CUBE 4.0 インストール
  1. ubuntu 20.04 nginx php mysql Webサーバー環境整備

    サーバー環境

    ubuntu 20.04 nginx php mysql Webサーバー環境…
  2. サーバー環境

    Laravel インストールメモ
  3. プログラミング

    python Anacondaを利用した開発環境の整備 jupter Noteb…
  4. Web・デザイン

    美しい文字 「Google Web Fonts」「Adobe Web Font…
  5. サーバー環境

    ubuntu 20.04 nginx php postgreSQL 12.5 W…
PAGE TOP