master
ブランチ master
LittleBeast / src / Std / Lib / Db / DbInterface.php
3.8 KB、90行 生 Blame 履歴
1<?php
2/*************************************************************
3# 076 License
4
5Copyright (c) テクニカル諏訪子
6
7Permission is hereby granted to any person obtaining a copy of the software
8Little Beast (the "Software") to use, modify, merge, copy, publish, distribute,
9sublicense, and/or sell copies of the Software, subject to the following conditions:
10
11 1. **Origin Attribution**:
12 - You must not misrepresent the origin of the Software; you must not claim
13 you created the original Software.
14 - If the Software is used in a product, you must either:
15 a. Provide clear attribution in the product's documentation, user interface,
16 or other visible areas, **OR**
17 b. Pay the original developers a fee they specify in writing.
18 2. **Usage Restriction**:
19 - The Software, or any derivative works, dependencies, or libraries
20 incorporating it, must not be used for censorship or to suppress freedom of
21 speech, expression, or creativity. Prohibited uses include, but are not
22 limited to:
23 - Censorship of so-called "hate speech", visuals, non-mainstream opinions,
24 ideas, or objective reality.
25 - Tools or systems designed to restrict access to information or
26 artistic works.
27 3. **Notice Preservation**:
28 - This license and the above copyright notice must remain intact in all copies
29 of the source code.
30
31THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
32INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
33PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
34HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
35CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
36OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
37 */
38namespace Std\Lib\Db;
39
40/**
41 * データベースのドライバ(Mysql等)
42 *
43 * query()・execute()の結果:
44 * fields 列の説明の配列(name、type等、ドライバ毎)
45 * rows 行の配列(列名 => 値。整数はint、浮動小数点数はfloat、NULLはnull、その他は文字列)
46 * affectedRows INSERT・UPDATE・DELETEで影響を受けた行数
47 * insertId AUTO_INCREMENTで作られたID
48 * warningCount 警告の数
49 * more (結果が複数ある場合)2つ目からの結果
50 */
51interface DbInterface {
52 /** 接続する(接続済みなら何もしない、失敗はDbException) */
53 public function connect(): bool;
54
55 /** 接続を閉じる */
56 public function close(): void;
57
58 /** 接続しているかどうか */
59 public function isConnected(): bool;
60
61 /** 接続がまだ生きているか確認する */
62 public function ping(): bool;
63
64 /** SQLをそのまま実行する(失敗はDbException) */
65 public function query(string $query): array;
66
67 /** プリペアドステートメント(プレースホルダは「?」)を準備し、IDを返す */
68 public function prepare(string $query): int;
69
70 /** プリペアドステートメントを実行する */
71 public function execute(int $statementId, array $params = []): array;
72
73 /** プリペアドステートメントを解放する */
74 public function demolish(int $statementId): bool;
75
76 /** トランザクションを開始する */
77 public function beginTransaction(): bool;
78
79 /** トランザクションをコミットする */
80 public function commit(): bool;
81
82 /** トランザクションをロールバックする */
83 public function rollback(): bool;
84
85 /** トランザクション中かどうか */
86 public function inTransaction(): bool;
87
88 /** 識別子(テーブル名・列名)を囲む */
89 public function quoteIdentifier(string $name): string;
90}