PHP 8.3.27 Released!

メタデータ

MySQL の結果セットは、メタデータを含んでいます。 メタデータは、結果セットで見つかったカラムの情報を説明するものです。 MySQL が送信した全てのメタデータは、 mysqli のインターフェイスを通じてアクセスできます。 この拡張モジュールは、受け取った情報に対してまったく変更を行いません。 仮にしたとしても、無視できる程度のものです。 MySQL のサーバーのバージョンによる違いは調整されません。

メタデータは、 mysqli_result インターフェイスを使ってアクセスします。

例1 結果セットのメタデータにアクセスする

<?php

mysqli_report
(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
$mysqli = new mysqli("example.com", "user", "password", "database");

$result = $mysqli->query("SELECT 1 AS _one, 'Hello' AS _two FROM DUAL");
var_dump($result->fetch_fields());

上の例の出力は以下となります。

array(2) {
 [0]=>
 object(stdClass)#3 (13) {
 ["name"]=>
 string(4) "_one"
 ["orgname"]=>
 string(0) ""
 ["table"]=>
 string(0) ""
 ["orgtable"]=>
 string(0) ""
 ["def"]=>
 string(0) ""
 ["db"]=>
 string(0) ""
 ["catalog"]=>
 string(3) "def"
 ["max_length"]=>
 int(1)
 ["length"]=>
 int(1)
 ["charsetnr"]=>
 int(63)
 ["flags"]=>
 int(32897)
 ["type"]=>
 int(8)
 ["decimals"]=>
 int(0)
 }
 [1]=>
 object(stdClass)#4 (13) {
 ["name"]=>
 string(4) "_two"
 ["orgname"]=>
 string(0) ""
 ["table"]=>
 string(0) ""
 ["orgtable"]=>
 string(0) ""
 ["def"]=>
 string(0) ""
 ["db"]=>
 string(0) ""
 ["catalog"]=>
 string(3) "def"
 ["max_length"]=>
 int(5)
 ["length"]=>
 int(5)
 ["charsetnr"]=>
 int(8)
 ["flags"]=>
 int(1)
 ["type"]=>
 int(253)
 ["decimals"]=>
 int(31)
 }
}

プリペアドステートメント

プリペアドステートメントを使って作られた結果セットのメタデータは、 アクセス方法も同じです。 mysqli_stmt::result_metadata() が、 適切な mysqli_result ハンドルを返してくれます。

例2 プリペアドステートメントのメタデータ

<?php

mysqli_report
(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
$mysqli = new mysqli("example.com", "user", "password", "database");

$stmt = $mysqli->prepare("SELECT 1 AS _one, 'Hello' AS _two FROM DUAL");
$stmt->execute();
$result = $stmt->result_metadata();
var_dump($result->fetch_fields());

参照

Found A Problem?

Learn How To Improve This PageSubmit a Pull RequestReport a Bug
+add a note

User Contributed Notes

There are no user contributed notes for this page.

AltStyle によって変換されたページ (->オリジナル) /