php8.5
Home/ Manual/ mysql_xdevapi / schema/ Schema::getCollection

Schema::getCollection

PHP function Edit on GitHub ✎

Get collection from schema

Description

mysql_xdevapi\Schema::getCollection(string $name): mysql_xdevapi\Collection

Get a collection from the schema.

Parameters

name

Collection name to retrieve.

Return Values

The Collection object for the selected collection.

Examples

mysql_xdevapi\Schema::getCollection example

php
<?php
$session = mysql_xdevapi\getSession("mysqlx://user:password@localhost");

$session->sql("DROP DATABASE IF EXISTS food")->execute();
$session->sql("CREATE DATABASE food")->execute();

$schema = $session->getSchema("food");
$schema->createCollection("trees");

// ...

$trees = $schema->getCollection("trees");

var_dump($trees);

The above example will output something similar to:

output
object(mysql_xdevapi\Collection)#3 (1) {
  ["name"]=>
  string(5) "trees"
}

Source: reference/mysql_xdevapi/mysql_xdevapi/schema/getcollection.xml · from the official PHP manual (php/doc-en)