« CollectionAdd::__construct
mysql_xdevapi\CollectionFind »

CollectionAdd::execute

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

CollectionAdd::execute — ステートメントを実行する

説明

public function mysql_xdevapi\CollectionAdd::execute(): mysql_xdevapi\Result

CRUD操作のリクエストを MySQL サーバーに送信するために execute メソッドは必須です。

パラメータ

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

戻り値

影響を受けた行数のような、操作の状態を確認するのに使われる Result オブジェクトを返します。

例

例1 mysql_xdevapi\CollectionAdd::execute() の例

<?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");

// ドキュメントをふたつ追加
$collection
  ->add('{"name": "Fred",  "age": 21, "job": "Construction"}')
  ->execute();

$collection
  ->add('{"name": "Wilma", "age": 23, "job": "Teacher"}')
  ->execute();

// 単一のJSONオブジェクトを使い、ドキュメントをふたつ追加
$result = $collection
  ->add(
    '{"name": "Bernie",
      "jobs": [{"title":"Cat Herder","Salary":42000}, {"title":"Father","Salary":0}],
      "hobbies": ["Sports","Making cupcakes"]}',
    '{"name": "Jane",
      "jobs": [{"title":"Scientist","Salary":18000}, {"title":"Mother","Salary":0}],
      "hobbies": ["Walking","Making pies"]}')
  ->execute();

// 最後の add() から生成された ID のリストを取得
$ids = $result->getGeneratedIds();
print_r($ids);
?>

上の例の出力は、 たとえば以下のようになります。

Array
(
    [0] => 00005b6b53610000000000000056
    [1] => 00005b6b53610000000000000057
)
関連キーワード:
execute   CollectionAdd   mysql   xdevapi   session   collection   title   Salary   ステートメント   addressbook   schema   操作   people   ドキュメント   jobs   hobbies   Making   construct   CollectionFind   information   available   リクエスト   MySQL   サーバー   送信
関連する関数・ページ:
mysql-xdevapi-collectionadd.construct   mysql-xdevapi-collection.add   mysql-xdevapi-result.getgeneratedids   mysql-xdevapi-executable.execute   class.mysql-xdevapi-collectionadd   mysql-xdevapi-collection.count