array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'pt_BR', ), 'this' => array ( 0 => 'mysql-xdevapi-schema.createcollection.php', 1 => 'Schema::createCollection', ), 'up' => array ( 0 => 'class.mysql-xdevapi-schema.php', 1 => 'mysql_xdevapi\\Schema', ), 'prev' => array ( 0 => 'mysql-xdevapi-schema.construct.php', 1 => 'Schema::__construct', ), 'next' => array ( 0 => 'mysql-xdevapi-schema.dropcollection.php', 1 => 'Schema::dropCollection', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'en', 'path' => 'reference/mysql_xdevapi/mysql_xdevapi/schema/createcollection.xml', ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); ?>
(No version information available, might only be in Git)
Schema::createCollection — Add collection to schema
$name
, string $validate
= ?): mysql_xdevapi\CollectionCreate a collection within the schema.
name
Collection name.
validate
Validation definition, as a JSON object.
The Collection object.
Versão | Descrição |
---|---|
8.0.20 | Added the optional validate parameter. |
Exemplo #1 mysql_xdevapi\Schema::createCollection() example
<?php
$session = mysql_xdevapi\getSession("mysqlx://user:password@localhost");
$session->sql("DROP DATABASE IF EXISTS food")->execute();
$session->sql("CREATE DATABASE food")->execute();
$session->sql("CREATE TABLE food.fruit(name text, rating text)")->execute();
$schema = $session->getSchema("food");
$schema->createCollection("trees");
print_r($schema->gettables());
print_r($schema->getcollections());
O exemplo acima produzirá algo semelhante a:
Array ( [fruit] => mysql_xdevapi\Table Object ( [name] => fruit ) ) Array ( [trees] => mysql_xdevapi\Collection Object ( [name] => trees ) )
Exemplo #2 mysql_xdevapi\Schema::createCollection() example
<?php
$collection = $schema->createCollection("mycollection", '{
"validation": {
"level": "strict",
"schema": {
"id": "http://json-schema.org/geo",
"description": "A geographical coordinate",
"type": "object",
"properties": {
"latitude": {
"type": "number"
},
"longitude": {
"type": "number"
}
},
"required": ["latitude", "longitude"]
}
}
}');
// Succeeds
$collection->add('{"latitude": 10, "longitude": 20}')->execute();
// Fails, invalid types (not numbers)
$collection->add('{"latitude": "lat", "longitude": "long"}')->execute();