PHP 8.3.4 Released!

Collection::existsInDatabase

(No version information available, might only be in Git)

Collection::existsInDatabaseコレクションがデータベースに存在するかをチェックする

説明

public mysql_xdevapi\Collection::existsInDatabase(): bool

コレクションオブジェクトが、データベース(スキーマ)内のコレクションを参照しているかを調べます。

パラメータ

この関数にはパラメータはありません。

戻り値

コレクションがデータベースに存在していれば true を返します。 そうでなければ、false を返します。

2つのカラム (doc と _id) で定義されたテーブルは、 コレクションと見なされます。 MySQL 8.0.21 以降では、doc, _id, _json_schema の3つのカラムで構成されたテーブルが コレクションと見なされます。 これに対してカラムを追加すると、 existsInDatabase() はコレクションとは見なさなくなります。

例1 mysql_xdevapi\Collection::existsInDatabase() の例

<?php
$session
= mysql_xdevapi\getSession("mysqlx://user:password@localhost");
$session->sql("DROP DATABASE IF EXISTS addressbook")->execute();
$session->sql("CREATE DATABASE addressbook")->execute();

$schema = $session->getSchema("addressbook");
$create = $schema->createCollection("people");

// ...

$collection = $schema->getCollection("people");

// ...

if (!$collection->existsInDatabase()) {
echo
"The collection no longer exists in the database named addressbook. What happened?";
}
?>
add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top