Documentation Home
MySQL PHP API
Download this Manual
PDF (US Ltr) - 2.4Mb
PDF (A4) - 2.4Mb
HTML Download (TGZ) - 250.9Kb
HTML Download (Zip) - 258.4Kb


MySQL PHP API  /  ...  /  Schema::getCollectionAsTable

5.25.6 Schema::getCollectionAsTable

Copyright 1997-2019 the PHP Documentation Group.

  • Schema::getCollectionAsTable

    Get collection table object

Description

public mysql_xdevapi\Table mysql_xdevapi\Schema::getCollectionAsTable(string name);

Get a collection, but as a Table object instead of a Collection object.

Parameters

name

Name of the collection to instantiate a Table object from.

Return Values

A table object for the collection.

Examples

Example 5.103 Schema::getCollectionAsTable example

<?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");
$collect = $schema->createCollection("people");
$collect->add('{"name": "Fred",  "age": 21, "job": "Construction"}')->execute();
$collect->add('{"name": "Wilma", "age": 23, "job": "Teacher"}')->execute();

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

var_dump($table);
var_dump($collection);

The above example will output something similar to:


object(mysql_xdevapi\Table)#4 (1) {
  ["name"]=>
  string(6) "people"
}

object(mysql_xdevapi\Collection)#5 (1) {
  ["name"]=>
  string(6) "people"
}