Chapter 5 Mysql_xdevapi

Table of Contents

5.1 Installing/Configuring
5.1.1 Requirements
5.1.2 Installation
5.1.3 Runtime Configuration
5.2 Predefined Constants
5.3 Examples
5.4 Mysql_xdevapi Functions
5.4.1 expression
5.4.2 getSession
5.5 BaseResult interface
5.5.1 BaseResult::getWarnings
5.5.2 BaseResult::getWarningsCount
5.6 Collection class
5.6.1 Collection::add
5.6.2 Collection::addOrReplaceOne
5.6.3 Collection::__construct
5.6.4 Collection::count
5.6.5 Collection::createIndex
5.6.6 Collection::dropIndex
5.6.7 Collection::existsInDatabase
5.6.8 Collection::find
5.6.9 Collection::getName
5.6.10 Collection::getOne
5.6.11 Collection::getSchema
5.6.12 Collection::getSession
5.6.13 Collection::modify
5.6.14 Collection::remove
5.6.15 Collection::removeOne
5.6.16 Collection::replaceOne
5.7 CollectionAdd class
5.7.1 CollectionAdd::__construct
5.7.2 CollectionAdd::execute
5.8 CollectionFind class
5.8.1 CollectionFind::bind
5.8.2 CollectionFind::__construct
5.8.3 CollectionFind::execute
5.8.4 CollectionFind::fields
5.8.5 CollectionFind::groupBy
5.8.6 CollectionFind::having
5.8.7 CollectionFind::limit
5.8.8 CollectionFind::lockExclusive
5.8.9 CollectionFind::lockShared
5.8.10 CollectionFind::offset
5.8.11 CollectionFind::sort
5.9 CollectionModify class
5.9.1 CollectionModify::arrayAppend
5.9.2 CollectionModify::arrayInsert
5.9.3 CollectionModify::bind
5.9.4 CollectionModify::__construct
5.9.5 CollectionModify::execute
5.9.6 CollectionModify::limit
5.9.7 CollectionModify::patch
5.9.8 CollectionModify::replace
5.9.9 CollectionModify::set
5.9.10 CollectionModify::skip
5.9.11 CollectionModify::sort
5.9.12 CollectionModify::unset
5.10 CollectionRemove class
5.10.1 CollectionRemove::bind
5.10.2 CollectionRemove::__construct
5.10.3 CollectionRemove::execute
5.10.4 CollectionRemove::limit
5.10.5 CollectionRemove::sort
5.11 ColumnResult class
5.11.1 ColumnResult::__construct
5.11.2 ColumnResult::getCharacterSetName
5.11.3 ColumnResult::getCollationName
5.11.4 ColumnResult::getColumnLabel
5.11.5 ColumnResult::getColumnName
5.11.6 ColumnResult::getFractionalDigits
5.11.7 ColumnResult::getLength
5.11.8 ColumnResult::getSchemaName
5.11.9 ColumnResult::getTableLabel
5.11.10 ColumnResult::getTableName
5.11.11 ColumnResult::getType
5.11.12 ColumnResult::isNumberSigned
5.11.13 ColumnResult::isPadded
5.12 CrudOperationBindable interface
5.12.1 CrudOperationBindable::bind
5.13 CrudOperationLimitable interface
5.13.1 CrudOperationLimitable::limit
5.14 CrudOperationSkippable interface
5.14.1 CrudOperationSkippable::skip
5.15 CrudOperationSortable interface
5.15.1 CrudOperationSortable::sort
5.16 DatabaseObject interface
5.16.1 DatabaseObject::existsInDatabase
5.16.2 DatabaseObject::getName
5.16.3 DatabaseObject::getSession
5.17 DocResult class
5.17.1 DocResult::__construct
5.17.2 DocResult::fetchAll
5.17.3 DocResult::fetchOne
5.17.4 DocResult::getWarnings
5.17.5 DocResult::getWarningsCount
5.18 Driver class
5.18.1 Driver::__construct
5.19 Exception class
5.20 Executable interface
5.20.1 Executable::execute
5.21 ExecutionStatus class
5.21.1 ExecutionStatus::__construct
5.22 Expression class
5.22.1 Expression::__construct
5.23 FieldMetadata class
5.23.1 FieldMetadata::__construct
5.24 Result class
5.24.1 Result::__construct
5.24.2 Result::getAutoIncrementValue
5.24.3 Result::getGeneratedIds
5.24.4 Result::getWarnings
5.24.5 Result::getWarningsCount
5.25 RowResult class
5.25.1 RowResult::__construct
5.25.2 RowResult::fetchAll
5.25.3 RowResult::fetchOne
5.25.4 RowResult::getColumnCount
5.25.5 RowResult::getColumnNames
5.25.6 RowResult::getColumns
5.25.7 RowResult::getWarnings
5.25.8 RowResult::getWarningsCount
5.26 Schema class
5.26.1 Schema::__construct
5.26.2 Schema::createCollection
5.26.3 Schema::dropCollection
5.26.4 Schema::existsInDatabase
5.26.5 Schema::getCollection
5.26.6 Schema::getCollectionAsTable
5.26.7 Schema::getCollections
5.26.8 Schema::getName
5.26.9 Schema::getSession
5.26.10 Schema::getTable
5.26.11 Schema::getTables
5.27 SchemaObject interface
5.27.1 SchemaObject::getSchema
5.28 Session class
5.28.1 Session::close
5.28.2 Session::commit
5.28.3 Session::__construct
5.28.4 Session::createSchema
5.28.5 Session::dropSchema
5.28.6 Session::executeSql
5.28.7 Session::generateUUID
5.28.8 Session::getClientId
5.28.9 Session::getSchema
5.28.10 Session::getSchemas
5.28.11 Session::getServerVersion
5.28.12 Session::killClient
5.28.13 Session::listClients
5.28.14 Session::quoteName
5.28.15 Session::releaseSavepoint
5.28.16 Session::rollback
5.28.17 Session::rollbackTo
5.28.18 Session::setSavepoint
5.28.19 Session::sql
5.28.20 Session::startTransaction
5.29 SqlStatement class
5.29.1 SqlStatement::bind
5.29.2 SqlStatement::__construct
5.29.3 SqlStatement::execute
5.29.4 SqlStatement::getNextResult
5.29.5 SqlStatement::getResult
5.29.6 SqlStatement::hasMoreResults
5.30 SqlStatementResult class
5.30.1 SqlStatementResult::__construct
5.30.2 SqlStatementResult::fetchAll
5.30.3 SqlStatementResult::fetchOne
5.30.4 SqlStatementResult::getAffectedItemsCount
5.30.5 SqlStatementResult::getColumnCount
5.30.6 SqlStatementResult::getColumnNames
5.30.7 SqlStatementResult::getColumns
5.30.8 SqlStatementResult::getGeneratedIds
5.30.9 SqlStatementResult::getLastInsertId
5.30.10 SqlStatementResult::getWarnings
5.30.11 SqlStatementResult::getWarningsCount
5.30.12 SqlStatementResult::hasData
5.30.13 SqlStatementResult::nextResult
5.31 Statement class
5.31.1 Statement::__construct
5.31.2 Statement::getNextResult
5.31.3 Statement::getResult
5.31.4 Statement::hasMoreResults
5.32 Table class
5.32.1 Table::__construct
5.32.2 Table::count
5.32.3 Table::delete
5.32.4 Table::existsInDatabase
5.32.5 Table::getName
5.32.6 Table::getSchema
5.32.7 Table::getSession
5.32.8 Table::insert
5.32.9 Table::isView
5.32.10 Table::select
5.32.11 Table::update
5.33 TableDelete class
5.33.1 TableDelete::bind
5.33.2 TableDelete::__construct
5.33.3 TableDelete::execute
5.33.4 TableDelete::limit
5.33.5 TableDelete::offset
5.33.6 TableDelete::orderby
5.33.7 TableDelete::where
5.34 TableInsert class
5.34.1 TableInsert::__construct
5.34.2 TableInsert::execute
5.34.3 TableInsert::values
5.35 TableSelect class
5.35.1 TableSelect::bind
5.35.2 TableSelect::__construct
5.35.3 TableSelect::execute
5.35.4 TableSelect::groupBy
5.35.5 TableSelect::having
5.35.6 TableSelect::limit
5.35.7 TableSelect::lockExclusive
5.35.8 TableSelect::lockShared
5.35.9 TableSelect::offset
5.35.10 TableSelect::orderby
5.35.11 TableSelect::where
5.36 TableUpdate class
5.36.1 TableUpdate::bind
5.36.2 TableUpdate::__construct
5.36.3 TableUpdate::execute
5.36.4 TableUpdate::limit
5.36.5 TableUpdate::orderby
5.36.6 TableUpdate::set
5.36.7 TableUpdate::where
5.37 Warning class
5.37.1 Warning::__construct
5.38 XSession class
5.38.1 XSession::__construct

Copyright 1997-2018 the PHP Documentation Group.

This extension provides access to the MySQL Document Store via the X DevAPI. The X DevAPI is a common API provided by multiple MySQL Connectors providing easy access to relational tables as well as collections of documents, which are represented in JSON, from a API with CRUD-style operations.

The X DevAPI uses the X Protocol, the new generation client-server protocol of the MySQL 8.0 server.

For general information about the MySQL Document Store, please refer to the MySQL Document Store chapter in the MySQL manual.

5.1 Installing/Configuring

Copyright 1997-2018 the PHP Documentation Group.

5.1.1 Requirements

Copyright 1997-2018 the PHP Documentation Group.

This extension requires a MySQL 8+ server with the X plugin enabled (default).

Prerequisite libraries for compiling this extension are: Boost, OpenSSL, and Protobuf.

5.1.2 Installation

Copyright 1997-2018 the PHP Documentation Group.

This PECL extension is not bundled with PHP.

An example installation procedure on Ubuntu 18.04 with PHP 7.2:


// Dependencies
$ apt install build-essential libprotobuf-dev libboost-dev openssl protobuf-compiler

// PHP with the desired extensions; php7.2-dev is required to compile
$ apt install php7.2-cli php7.2-dev php7.2-mysql php7.2-pdo php7.2-xml

// Compile the extension
$ pecl install mysql_xdevapi

The pecl install command does not enable PHP extensions (by default) and enabling PHP extensions can be done in several ways. Another PHP 7.2 on Ubuntu 18.04 example:


// Create its own ini file
$ echo "extension=mysql_xdevapi.so" > /etc/php/7.2/mods-available/mysql_xdevapi.ini

// Use the 'phpenmod' command (note: it's Debian/Ubuntu specific)
$ phpenmod -v 7.2 -s ALL mysql_xdevapi

// A 'phpenmod' alternative is to manually symlink it
// $ ln -s /etc/php/7.2/mods-available/mysql_xdevapi.ini /etc/php/7.2/cli/conf.d/20-mysql_xdevapi.ini

// Let's see which MySQL extensions are enabled now
$ php -m |grep mysql

mysql_xdevapi
mysqli
mysqlnd
pdo_mysql

Information for installing this PECL extension may be found in the manual chapter titled Installation of PECL extensions. Additional information such as new releases, downloads, source files, maintainer information, and a CHANGELOG, can be located here: http://pecl.php.net/package/mysql_xdevapi.

5.1.3 Runtime Configuration

Copyright 1997-2018 the PHP Documentation Group.

The behaviour of these functions is affected by settings in php.ini.

Table 5.1 Mysql_xdevapi Configure Options

NameDefaultChangeableChangelog
xmysqlnd.collect_memory_statistics0PHP_INI_SYSTEM 
xmysqlnd.collect_statistics1PHP_INI_ALL 
xmysqlnd.debug PHP_INI_SYSTEM 
xmysqlnd.mempool_default_size16000PHP_INI_ALL 
xmysqlnd.net_read_timeout31536000PHP_INI_SYSTEM 
xmysqlnd.trace_alloc PHP_INI_SYSTEM 


Here's a short explanation of the configuration directives.

xmysqlnd.collect_memory_statistics integer

xmysqlnd.collect_statistics integer

xmysqlnd.debug string

xmysqlnd.mempool_default_size integer

xmysqlnd.net_read_timeout integer

xmysqlnd.trace_alloc string

5.2 Predefined Constants

Copyright 1997-2018 the PHP Documentation Group.

The constants below are defined by this extension, and will only be available when the extension has either been compiled into PHP or dynamically loaded at runtime.

MYSQLX_CLIENT_SSL (integer)
MYSQLX_TYPE_DECIMAL (integer)
MYSQLX_TYPE_TINY (integer)
MYSQLX_TYPE_SHORT (integer)
MYSQLX_TYPE_SMALLINT (integer)
MYSQLX_TYPE_MEDIUMINT (integer)
MYSQLX_TYPE_INT (integer)
MYSQLX_TYPE_BIGINT (integer)
MYSQLX_TYPE_LONG (integer)
MYSQLX_TYPE_FLOAT (integer)
MYSQLX_TYPE_DOUBLE (integer)
MYSQLX_TYPE_NULL (integer)
MYSQLX_TYPE_TIMESTAMP (integer)
MYSQLX_TYPE_LONGLONG (integer)
MYSQLX_TYPE_INT24 (integer)
MYSQLX_TYPE_DATE (integer)
MYSQLX_TYPE_TIME (integer)
MYSQLX_TYPE_DATETIME (integer)
MYSQLX_TYPE_YEAR (integer)
MYSQLX_TYPE_NEWDATE (integer)
MYSQLX_TYPE_ENUM (integer)
MYSQLX_TYPE_SET (integer)
MYSQLX_TYPE_TINY_BLOB (integer)
MYSQLX_TYPE_MEDIUM_BLOB (integer)
MYSQLX_TYPE_LONG_BLOB (integer)
MYSQLX_TYPE_BLOB (integer)
MYSQLX_TYPE_VAR_STRING (integer)
MYSQLX_TYPE_STRING (integer)
MYSQLX_TYPE_CHAR (integer)
MYSQLX_TYPE_BYTES (integer)
MYSQLX_TYPE_INTERVAL (integer)
MYSQLX_TYPE_GEOMETRY (integer)
MYSQLX_TYPE_JSON (integer)
MYSQLX_TYPE_NEWDECIMAL (integer)
MYSQLX_TYPE_BIT (integer)
MYSQLX_LOCK_DEFAULT (integer)
MYSQLX_LOCK_NOWAIT (integer)
MYSQLX_LOCK_SKIP_LOCKED (integer)

5.3 Examples

Copyright 1997-2018 the PHP Documentation Group.

The central entry point to the X DevAPI is the mysql_xdevapi\getSession function, which receives a URI to a MySQL 8.0 Server and returns a mysql_xdevap\Session object.

Example 5.1 Connecting to a MySQL Server


<?php
$session = mysql_xdevapi\getSession("mysqlx://user:password@host");
if ($session === NULL) {
  die("Connection could not be established");
} 

// ... use $session
?>


The session provides full access to the API. For a new MySQL Server installation, the first step is to create a database schema with a collection to store data:

Example 5.2 Creating a Schema and Collection on the MySQL Server


<?php
$schema = $session->createSchema("test");
$collection = $schema->createCollection("example");
?>


When storing data, typically json_encode is used to encode the data into JSON, which can then be stored inside a collection.

The following example stores data into the collection we created earlier, and then retrieve parts of it again.

Example 5.3 Storing and Retrieving Data


<?php
$marco = [
  "name" => "Marco",
  "age"  => 19,
  "job"  => "Programmer"
];
$mike = [
  "name" => "Mike",
  "age"  => 39,
  "job"  => "Manager"
];

$schema = $session->getSchema("test");
$collection = $schema->getCollection("example");

$collection->add($marco, $mike)->execute();

var_dump($collection->find("name = 'Mike'")->execute()->fetchOne());
?>

  

The above example will output something similar to:

   
array(4) {
  ["_id"]=>
  string(28) "00005ad66aaf0000000000000003"
  ["age"]=>
  int(39)
  ["job"]=>
  string(7) "Manager"
  ["name"]=>
  string(4) "Mike"
}


The example demonstrates that the MySQL Server adds an extra field named _id, which serves as primary key to the document.

The example also demonstrates that retrieved data is sorted alphabetically. That specific order comes from the efficient binary storage inside the MySQL server, but it should not be relied upon. Refer to the MySQL JSON datatype documentation for details.

Optionally use PHP's iterators fetch multiple documents:

Example 5.4 Fetching and Iterating Multiple Documents


<?php
$result = $collection->find()->execute());
foreach ($result as $doc) {
  echo "${doc["name"]} is a ${doc["job"]}.\n";
}
?>

  

The above example will output something similar to:

   
Marco is a Programmer.
Mike is a Manager.


5.4 Mysql_xdevapi Functions

Copyright 1997-2018 the PHP Documentation Group.

5.4.1 expression

Copyright 1997-2018 the PHP Documentation Group.

  • expression

    Bind prepared statement variables as parameters

Description

object mysql_xdevapi\expression(string expression);

Warning

This function is currently not documented; only its argument list is available.

Parameters

expression

Return Values

Examples

Example 5.5 mysql_xdevapi\Expression example


<?php
$expression = mysql_xdevapi\Expression("[age,job]");

$res  = $coll->find("age > 30")->fields($expression)->limit(3)->execute();
$data = $res->fetchAll();

print_r($data);
?>

   

The above example will output something similar to:


<?php


5.4.2 getSession

Copyright 1997-2018 the PHP Documentation Group.

  • getSession

    Connect to a MySQL server

Description

mysql_xdevapi\Session mysql_xdevapi\getSession(string uri);

Connects to the MySQL server.

Parameters

uri

The URI to the MySQL server, such as mysqlx://user:password@host.

URI format:

scheme://[user[:[password]]@]target[:port][?attribute1=value1&attribute2=value2...

  • scheme: required, the connection protocol

    In mysql_xdevapi it is always 'mysqlx' (for X Protocol)

  • user: optional, the MySQL user account for authentication

  • password: optional, the MySQL user's password for authentication

  • target: required, the server instance the connection refers to:

    * TCP connection (host name, IPv4 address, or IPv6 address)

    * Unix socket path (local file path)

    * Windows named-pipe (local file path)

  • port: optional, network port of MySQL server.

    by default port for X Protocol is 33060

  • ?attribute=value: this element is optional and specifies a data dictionary that contains options, e.g. for encrypted connections or 'auth'. For additional information, see Command Options for Encrypted Connections.

    The following values for 'auth' attribute are supported (authentication mechanism):

    • plain

    • mysql41

    • external

    • sha256_mem

Example 5.6 URI examples

mysqlx://foobar
mysqlx://root@localhost?socket=%2Ftmp%2Fmysqld.sock%2F
mysqlx://foo:bar@localhost:33060
mysqlx://foo:bar@localhost:33160?ssl-mode=disabled
mysqlx://foo:bar@localhost:33260?ssl-mode=required
mysqlx://foo:bar@localhost:33360?ssl-mode=required&auth=mysql41
mysqlx://foo:bar@(/path/to/socket)
mysqlx://foo:bar@(/path/to/socket)?auth=sha256_mem
mysqlx://foo:bar@[localhost:33060, 127.0.0.1:33061]
mysqlx://foobar?ssl-ca=(/path/to/ca.pem)&ssl-crl=(/path/to/crl.pem)
mysqlx://foo:bar@[localhost:33060, 127.0.0.1:33061]?ssl-mode=disabled

For related information, see MySQL Shell's Connecting using a URI String.

Return Values

A mysql_xdevap\Session object.

Examples

Example 5.7 mysql_xdevapi\getSession example


<?php
$session = mysql_xdevapi\getSession("mysqlx://user:password@host");
if ($session === NULL) {
    die("Connection could not be established");
}

$schemas = $session->getSchemas();
print_r($schemas);

$mysql_version = $session->getServerVersion();
print_r($mysql_version);

var_dump($collection->find("name = 'Alfred'")->execute()->fetchOne());
?>

   

The above example will output something similar to:


Array
(
    [0] => mysql_xdevapi\Schema Object
        (
            [name] => helloworld
        )
    [1] => mysql_xdevapi\Schema Object
        (
            [name] => information_schema
        )
    [2] => mysql_xdevapi\Schema Object
        (
            [name] => mysql
        )
    [3] => mysql_xdevapi\Schema Object
        (
            [name] => performance_schema
        )
    [4] => mysql_xdevapi\Schema Object
        (
            [name] => sys
        )
)

80012

array(4) {
  ["_id"]=>
  string(28) "00005ad66abf0001000400000003"
  ["age"]=>
  int(42)
  ["job"]=>
  string(7) "Butler"
  ["name"]=>
  string(4) "Alfred"
}


5.5 BaseResult interface

Copyright 1997-2018 the PHP Documentation Group.

 mysql_xdevapi\BaseResult {
mysql_xdevapi\BaseResult Methods  abstract public array mysql_xdevapi\BaseResult::getWarnings();
  abstract public integer mysql_xdevapi\BaseResult::getWarningsCount();
}

5.5.1 BaseResult::getWarnings

Copyright 1997-2018 the PHP Documentation Group.

  • BaseResult::getWarnings

    Fetch warnings from last operation

Description

abstract public array mysql_xdevapi\BaseResult::getWarnings();

Fetches the warnings generated by the MySQL server from the last operation.

Parameters

This function has no parameters.

Return Values

An array of warnings raised by the last operation, or an empty array if no warnings are present.

Examples

Example 5.8 mysql_xdevapi\RowResult::getWarnings example


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

$session->sql("CREATE DATABASE foo")->execute();
$session->sql("CREATE TABLE foo.test_table(x int)")->execute();

$schema = $session->getSchema("foo");
$table  = $schema->getTable("test_table");

$table->insert(['x'])->values([1])->values([2])->execute();

$res = $table->select(['x/0 as bad_x'])->execute();
$warnings = $res->getWarnings();

print_r($warnings);
?>

   

The above example will output something similar to:


Array
(
    [0] => mysql_xdevapi\Warning Object
        (
            [message] => Division by 0
            [level] => 2
            [code] => 1365
        )
    [1] => mysql_xdevapi\Warning Object
        (
            [message] => Division by 0
            [level] => 2
            [code] => 1365
        )
)


5.5.2 BaseResult::getWarningsCount

Copyright 1997-2018 the PHP Documentation Group.

  • BaseResult::getWarningsCount

    Fetch warning count from last operation

Description

abstract public integer mysql_xdevapi\BaseResult::getWarningsCount();

Returns the number of warnings raised by the last operation. Specifically, these warnings are raised by the MySQL server.

Parameters

This function has no parameters.

Return Values

The number of warnings from the last operation.

Examples

Example 5.9 mysql_xdevapi\RowResult::getWarningsCount example


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

$session->sql("DROP DATABASE IF EXISTS foo")->execute();
$session->sql("CREATE DATABASE foo")->execute();
$session->sql("CREATE TABLE foo.test_table(x int)")->execute();

$schema = $session->getSchema("foo");
$table  = $schema->getTable("test_table");

$table->insert(['x'])->values([1])->values([2])->execute();

$res = $table->select(['x/0 as bad_x'])->execute();

echo $res->getWarningsCount();
?>

   

The above example will output something similar to:


2


5.6 Collection class

Copyright 1997-2018 the PHP Documentation Group.

 mysql_xdevapi\Collection {
mysql_xdevapi\Collection , mysql_xdevapi\SchemaObject Properties  public name ;
Methods  public mysql_xdevapi\Result mysql_xdevapi\Collection::add(mixed document);
  public mysql_xdevapi\Result mysql_xdevapi\Collection::addOrReplaceOne(string id,
                                                                        string doc);

  public integer mysql_xdevapi\Collection::count();
  public void mysql_xdevapi\Collection::createIndex(string index_name,
                                                    string index_desc_json);

  public bool mysql_xdevapi\Collection::dropIndex(string index_name);
  public bool mysql_xdevapi\Collection::existsInDatabase();
  public mysql_xdevapi\CollectionFind mysql_xdevapi\Collection::find(string search_condition);
  public string mysql_xdevapi\Collection::getName();
  public Document mysql_xdevapi\Collection::getOne(string id);
  public Schema Object mysql_xdevapi\Collection::getSchema();
  public Session mysql_xdevapi\Collection::getSession();
  public mysql_xdevapi\CollectionModify mysql_xdevapi\Collection::modify(string search_condition);
  public mysql_xdevapi\CollectionRemove mysql_xdevapi\Collection::remove(string search_condition);
  public mysql_xdevapi\Result mysql_xdevapi\Collection::removeOne(string id);
  public mysql_xdevapi\Result mysql_xdevapi\Collection::replaceOne(string id,
                                                                   string doc);

}

name

5.6.1 Collection::add

Copyright 1997-2018 the PHP Documentation Group.

  • Collection::add

    Add collection document

Description

public mysql_xdevapi\Result mysql_xdevapi\Collection::add(mixed document);

Triggers the insertion of the given document(s) into the collection, and multiple variants of this method are supported. Options include:

  1. Add a single document as a JSON string.

  2. Add a single document as an array as: [ 'field' => 'value', 'field2' => 'value2' ... ]

  3. A mix of of both, and multiple documents can be added in the same operation.

Parameters

document

One or multiple documents, and this can be either JSON or an array of fields with their associated values. This cannot be an empty array.

The MySQL server automatically generates unique _id values for each document (recommended), although this can be manually added as well. This value must be unique as otherwise the add operation will fail.

Return Values

A Result object that can be used to query the number of affected items, the number warnings generated by the operation, or to fetch a list of generated IDs for the inserted documents.

Examples

Example 5.10 mysql_xdevapi\Collection::add 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");
$create = $schema->createCollection("people");

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

// Add two documents
$collection->add('{"name": "Fred",  "age": 21, "job": "Construction"}')->execute();
$collection->add('{"name": "Wilma", "age": 23, "job": "Teacher"}')->execute();

// Add two documents using a single JSON object
$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();

// Fetch a list of generated ID's from the last add()
$ids = $result->getGeneratedIds();
print_r($ids);
?>

   

The above example will output something similar to:


Array
(
    [0] => 00005b6b53610000000000000056
    [1] => 00005b6b53610000000000000057
)


5.6.2 Collection::addOrReplaceOne

Copyright 1997-2018 the PHP Documentation Group.

  • Collection::addOrReplaceOne

    Add or replace collection document

Description

public mysql_xdevapi\Result mysql_xdevapi\Collection::addOrReplaceOne(string id,
                                                                      string doc);

Add a new document, or replace a document if it already exists.

Here are several scenarios for this method:

  • If neither the id or any unique key values conflict with any document in the collection, then the document is added.

  • If the id does not match any document but one or more unique key values conflict with a document in the collection, then an error is raised.

  • If id matches an existing document and no unique keys are defined for the collection, then the document is replaced.

  • If id matches an existing document, and either all unique keys in the replacement document match that same document or they don't conflict with any other documents in the collection, then the document is replaced.

  • If id matches an existing document and one or more unique keys match a different document from the collection, then an error is raised.

Parameters

id

This is the filter id. If this id or any other field that has a unique index already exists in the collection, then it will update the matching document instead.

doc

This is the document to add or replace, which is a JSON string.

Return Values

A Result object.

Examples

Example 5.11 mysql_xdevapi\Collection::addOrReplaceOne example


<?php
/*
    Assuming that $coll is a valid collection object, the following call to addOrReplaceOne
    will search for a document with the ID 121 and will either replace it or add a new one with
    that ID.
*/
$res = $coll->addOrReplaceOne('121', '{"name": "Sakila", "age": 30, "job": "Radio", "_id": "121" }');

?>


5.6.3 Collection::__construct

Copyright 1997-2018 the PHP Documentation Group.

  • Collection::__construct

    Collection constructor

Description

private mysql_xdevapi\Collection::__construct();

Parameters

This function has no parameters.

5.6.4 Collection::count

Copyright 1997-2018 the PHP Documentation Group.

  • Collection::count

    Get document count

Description

public integer mysql_xdevapi\Collection::count();

This functionality is similar to a SELECT COUNT(*) SQL operation against the MySQL server for the current schema and collection. In other words, it counts the number of documents in the collection.

Parameters

This function has no parameters.

Return Values

The number of documents in the collection.

5.6.5 Collection::createIndex

Copyright 1997-2018 the PHP Documentation Group.

  • Collection::createIndex

    Create collection index

Description

public void mysql_xdevapi\Collection::createIndex(string index_name,
                                                  string index_desc_json);

Creates an index on the collection.

An exception is thrown if an index with the same name already exists, or if index definition is not correctly formed.

Parameters

index_name

The name of the index that to create. This name must be a valid index name as accepted by the CREATE INDEX SQL query.

index_desc_json

Definition of the index to create. It contains an array of IndexField objects, and each object describes a single document member to include in the index, and an optional string for the type of index that might be INDEX (default) or SPATIAL.

A single IndexField description consists of the following fields:

  • field: string, the full document path to the document member or field to be indexed.

  • type: string, one of the supported SQL column types to map the field into. For numeric types, the optional UNSIGNED keyword may follow. For the TEXT type, the length to consider for indexing may be added.

  • required: bool, (optional) true if the field is required to exist in the document. Defaults to FALSE, except for GEOJSON where it defaults to TRUE.

  • options: integer, (optional) special option flags for use when decoding GEOJSON data.

  • srid: integer, (optional) srid value for use when decoding GEOJSON data.

It is an error to include other fields not described above in IndexDefinition or IndexField documents.

Return Values

Examples

Example 5.12 mysql_xdevapi\Collection::createIndex example


<?php
// Creating index on single field
$coll->createIndex("index1",{fields:[{field:"$.name", type: "TEXT(15)"}]})->execute();

// Creating index with unique set to false
$coll->createIndex("index2",{fields:[{field:"$.name", type: "TEXT(15)"}],unique : false})->execute();

// Creating an index with required option set to true
$coll->createIndex("index3",{fields:[{field:"$.name", type: "TEXT(15)",required : true}]})->execute();

// Creating index on multiple feilds
$coll->createIndex("index4",{fields:[{field:"$.name", type: "TEXT(20)"},{field:"$.age",type: "INTEGER"}]})->execute();

// Creating spatial index
$coll->createIndex("index1",{fields:[{field:"$.name", type: "GEOJSON"}],type : "SPATIAL"})->execute();
?>


5.6.6 Collection::dropIndex

Copyright 1997-2018 the PHP Documentation Group.

  • Collection::dropIndex

    Drop collection index

Description

public bool mysql_xdevapi\Collection::dropIndex(string index_name);

Drop an index with the given name. Silently succeeds if the index does not exist (no error or warning raised). To confirm the drop has been executed the user should check the boolean return type.

Parameters

index_name

The name of the index that has to be dropped.

Return Values

The functions return a boolean value, true if the drop has succeed and false in the other case.

Examples

Example 5.13 mysql_xdevapi\Collection::dropIndex example


<?php

/* ... */

?>


5.6.7 Collection::existsInDatabase

Copyright 1997-2018 the PHP Documentation Group.

  • Collection::existsInDatabase

    Check if collection exists in database

Description

public bool mysql_xdevapi\Collection::existsInDatabase();

Checks if the Collection object refers to a collection in the database.

Parameters

This function has no parameters.

Return Values

Returns TRUE if collection exists in the database, else FALSE if it does not.

Examples

Example 5.14 mysql_xdevapi\Collection::existsInDatabase example


<?php

// Assuming $coll is a valid Collection object

if( !$coll->existsInDatabase() ) {
    print('Sorry, but the collection do not exists in the provided database!');
}
?>


5.6.8 Collection::find

Copyright 1997-2018 the PHP Documentation Group.

  • Collection::find

    Search for document

Description

public mysql_xdevapi\CollectionFind mysql_xdevapi\Collection::find(string search_condition);

Search a database collection for a document or set of documents. The returned documents are contained in the CollectionFind object that can be used further to fetch one or all the documents.

Parameters

search_condition

Although optional, normally a condition is defined to limit the results to a subset of documents.

Multiple elements might build the condition and the syntax supports parameter binding. The expression used as search condition must be a valid SQL expression. If no search condition is provided (field empty) then find('true') is assumed.

Return Values

A CollectionFind object that can use used to verify the operation or fetch found documents.

Examples

Example 5.15 mysql_xdevapi\Collection::find example


<?php

// Assuming $coll is a valid Collection object

$coll->add('{"name": "Marco",      "age": 19, "job": "Programmatore"}')->execute();
$coll->add('{"name": "Lonardo",    "age": 59, "job": "Paninaro"}')->execute();
$coll->add('{"name": "Riccardo",   "age": 27, "job": "Cantante"}')->execute();
$coll->add('{"name": "Carlotta",   "age": 23, "job": "Programmatrice"}')->execute();
$coll->add('{"name": "Carlo",      "age": 25, "job": "Programmatore"}')->execute();
$coll->add('{"name": "Mariangela", "age": 41, "job": "Programmatrice"}')->execute();
$coll->add('{"name": "Alfredo",    "age": 27, "job": "Programmatore"}')->execute();
$coll->add('{"name": "Antonella",  "age": 42, "job": "Studente"}')->execute();
$coll->add('{"name": "Monica",     "age": 35, "job": "Ballerino"}')->execute();
$coll->add('{"name": "Giulio",     "age": 29, "job": "Disoccupato"}')->execute();
$coll->add('{"name": "Lucia",      "age": 47, "job": "Barista"}')->execute();
$coll->add('{"name": "Filippo",    "age": 31, "job": "Spazzino"}')->execute();
$coll->add('{"name": "Alessandra", "age": 15, "job": "Barista"}')->execute();
$coll->add('{"name": "Massimo",    "age": 22, "job": "Programmatore"}')->execute();
$coll->add('{"name": "Carlo",      "age": 37, "job": "Calciatore"}')->execute();

/*
   This query will look for up to 2 documents in the Collection sorted by age (descending),
   the documents must have the job 'Programmatore' and the age field higher or equal to 20

   The actual resulting documents are 'Carlo' and 'Alfredo'
*/

$obj  = $coll->find('job like :job and age > :age')->fields('age');
$res  = $obj->bind(['job' => 'Programmatore', 'age' => 20])->sort('age desc')->limit(2);
$data = $res->execute()->fetchAll();

// The search condition mighe also be very complex and use multiple functions
$res  = $coll->find('(1>5) IN (true,false) && {"title":"Spavatore"} NOT IN jobs && CAST(_id AS SIGNED) > 2')->execute();

?>


5.6.9 Collection::getName

Copyright 1997-2018 the PHP Documentation Group.

  • Collection::getName

    Get collection name

Description

public string mysql_xdevapi\Collection::getName();

Retrieve the collection's name.

Parameters

This function has no parameters.

Return Values

The collection name, as a string.

5.6.10 Collection::getOne

Copyright 1997-2018 the PHP Documentation Group.

  • Collection::getOne

    Get one document

Description

public Document mysql_xdevapi\Collection::getOne(string id);

This is a shortcut for Collection.find("_id = :id").bind("id", id).execute().fetchOne();.

Parameters

id

The document ID in the collection.

Return Values

The collection object, or NULL if the ID does not match a document.

Examples

Example 5.16 mysql_xdevapi\Collection::getOne example


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

$schema = $session->getSchema('test');
$coll   = $schema->getCollection('test_collection');

$coll->add('{"_id": "1", "name": "Marco",      "age": 19, "job": "Programmatore"}')->execute();
$coll->add('{"_id": "2", "name": "Lonardo",    "age": 59, "job": "Paninaro"}')->execute();
$coll->add('{"_id": "3", "name": "Riccardo",   "age": 27, "job": "Cantante"}')->execute();
$coll->add('{"_id": "4", "name": "Carlotta",   "age": 23, "job": "Programmatrice"}')->execute();
$coll->add('{"_id": "5", "name": "Carlo",      "age": 25, "job": "Programmatore"}')->execute();

print_r( $coll->getOne(3) );
print_r( $coll->getOne(5) );
?>

   

The above example will output something similar to:


Array
(
    [_id] => 3
    [age] => 27
    [job] => Cantante
    [name] => Riccardo
)
Array
(
    [_id] => 5
    [age] => 25
    [job] => Programmatore
    [name] => Carlo
)


5.6.11 Collection::getSchema

Copyright 1997-2018 the PHP Documentation Group.

  • Collection::getSchema

    Get schema object

Description

public Schema Object mysql_xdevapi\Collection::getSchema();

Retrieve the schema object that contains the collection.

Parameters

This function has no parameters.

Return Values

The schema object on success, or NULL if the object cannot be retrieved for the given collection.

Examples

Example 5.17 mysql_xdevapi\Collection::getSchema example


<?php

$schema = $collection->getSchema();

?>


5.6.12 Collection::getSession

Copyright 1997-2018 the PHP Documentation Group.

  • Collection::getSession

    Get session object

Description

public Session mysql_xdevapi\Collection::getSession();

Retrieve a session object that contains the collection.

Parameters

This function has no parameters.

Return Values

The session object.

Examples

Example 5.18 mysql_xdevapi\Collection::getSession example


<?php

$session = $coll->getSession();

?>


5.6.13 Collection::modify

Copyright 1997-2018 the PHP Documentation Group.

  • Collection::modify

    Modify collection documents

Description

public mysql_xdevapi\CollectionModify mysql_xdevapi\Collection::modify(string search_condition);

Modify collections that meet specific search conditions. Multiple operations are allowed, and parameter binding is supported.

Parameters

search_condition

Must be a valid SQL expression used to match the documents to modify. This expression might be as simple as TRUE, which matches all documents, or it might use functions and operators such as 'CAST(_id AS SIGNED) >= 10', 'age MOD 2 = 0 OR age MOD 3 = 0', or '_id IN ["2","5","7","10"]'.

Return Values

If the operation is not executed, then the function will return a Modify object that can be used to add additional modify operations.

If the modify operation is executed, then the returned object will contain the result of the operation.

Examples

Example 5.19 mysql_xdevapi\Collection::modify example


<?php
// Assuming $coll is a valid Collection object

// To all the documents with the 'job' field like 'Programmatore' or 'Cantante' append two new jobs: Volontario and Tassinaro
$coll->modify("job in ('Programmatore', 'Cantante')")->arrayAppend('job', 'Volontario')->arrayAppend('job', 'Tassinaro')->execute();

// Remove the 'age' field from all the docs with 'ordinal' between 1 and 9
$coll->modify('ordinal >= 1 and ordinal <= 9')->unset(['age'])->execute();

/*
 The modify operation is split in two lines, the object returned by a not executed 'modify'
 holds the state of the current modify (it might be executed later)
*/
$obj = $coll->modify('age > :age1 and age < :age2')->bind(['age1' => 25, 'age2' => 40]);
$data = $obj->sort(['_id desc'])->limit(2)->replace('job', 'Disoccupato')->execute();
?>


5.6.14 Collection::remove

Copyright 1997-2018 the PHP Documentation Group.

  • Collection::remove

    Remove collection documents

Description

public mysql_xdevapi\CollectionRemove mysql_xdevapi\Collection::remove(string search_condition);

Remove collections that meet specific search conditions. Multiple operations are allowed, and parameter binding is supported.

Parameters

search_condition

Must be a valid SQL expression used to match the documents to modify. This expression might be as simple as TRUE, which matches all documents, or it might use functions and operators such as 'CAST(_id AS SIGNED) >= 10', 'age MOD 2 = 0 OR age MOD 3 = 0', or '_id IN ["2","5","7","10"]'.

Return Values

If the operation is not executed, then the function will return a Remove object that can be used to add additional remove operations.

If the remove operation is executed, then the returned object will contain the result of the operation.

Examples

Example 5.20 mysql_xdevapi\Collection::remove example


<?php
// Assuming $coll is a valid Collection object

// Remove all the documents for which the 'age' field is between 20 and 50
$coll->remove('age > :age_from and age < :age_to')->bind(['age_from' => 20, 'age_to' => 50])->limit(7)->execute();

// Select for removal all the documents, sort them by age (descending) and remove only the first 2
$coll->remove('true')->sort('age desc')->limit(2)->execute();
?>


5.6.15 Collection::removeOne

Copyright 1997-2018 the PHP Documentation Group.

  • Collection::removeOne

    Remove one collection document

Description

public mysql_xdevapi\Result mysql_xdevapi\Collection::removeOne(string id);

Remove one document from the collection with the correspending ID. This is a shortcut for Collection.remove("_id = :id").bind("id", id).execute().

Parameters

id

The ID of the collection document to remove.

Return Values

A Result object that can be used to query the number of affected items or the number warnings generated by the operation.

Examples

Example 5.21 mysql_xdevapi\Collection::removeOne example


<?php
// Assuming $coll is a valid collection object

$res = $coll->removeOne('00005ad66abf0001000400000003');

if( $res->getAffectedItemsCount() == 0 ) {
    print('The document with ID 00005ad66abf0001000400000003 seems to not exists, nothing was removed');
}
?>


5.6.16 Collection::replaceOne

Copyright 1997-2018 the PHP Documentation Group.

  • Collection::replaceOne

    Replace one collection document

Description

public mysql_xdevapi\Result mysql_xdevapi\Collection::replaceOne(string id,
                                                                 string doc);

Updates (or replaces) the document identified by ID, if it exists.

Parameters

id

ID of the document to replace or update.

doc

Collection document to update or replace the document matching the id parameter.

This document can be either a document object or a valid JSON string describing the new document.

Return Values

A Result object that can be used to query the number of affected items and the number warnings generated by the operation.

Examples

Example 5.22 mysql_xdevapi\Collection::replaceOne example


<?php
// Assuming $coll is a valid Collection object

// Replace the document with the ID:00005ad66abf0001000400000003 with the provided new document
$coll->replaceOne('00005ad66abf0001000400000003', '{"name": "Filip", "age": 20, "job": "Programmatore"}');

// In this example I'm extracting the document with ID 16, the after some modifications
// I'm replacing that document with the modified one.
$doc = $coll->getOne(16);
$doc["age"] = "55";
$doc["job"] = "SeniorProgrammatore";
$coll->replaceOne(16, $doc);

?>


5.7 CollectionAdd class

Copyright 1997-2018 the PHP Documentation Group.

 mysql_xdevapi\CollectionAdd {
mysql_xdevapi\CollectionAdd , mysql_xdevapi\Executable Methods  public mysql_xdevapi\Result mysql_xdevapi\CollectionAdd::execute();
}

5.7.1 CollectionAdd::__construct

Copyright 1997-2018 the PHP Documentation Group.

  • CollectionAdd::__construct

    CollectionAdd constructor

Description

private mysql_xdevapi\CollectionAdd::__construct();

Warning

This function is currently not documented; only its argument list is available.

Parameters

This function has no parameters.

Examples

Example 5.23 mysql_xdevapi\CollectionAdd::__construct example


<?php

/* ... */

?>


5.7.2 CollectionAdd::execute

Copyright 1997-2018 the PHP Documentation Group.

  • CollectionAdd::execute

    Execute the statement

Description

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

The execute method is required to send the CRUD operation request to the MySQL server.

Parameters

This function has no parameters.

Return Values

A Result object that can be used to verify the status of the operation, such as the number of affected rows.

Examples

Example 5.24 mysql_xdevapi\CollectionAdd::execute example


<?php
// Assuming $coll is a valid collection Object, the call to 'execute' is needed to trigger
// the submission of the CRUD operation to the server.
$coll->add('{"name": "Marco",      "age": 19, "job": "Programmatore"}')->execute();

?>


5.8 CollectionFind class

Copyright 1997-2018 the PHP Documentation Group.

 mysql_xdevapi\CollectionFind {
mysql_xdevapi\CollectionFind , mysql_xdevapi\Executable , mysql_xdevapi\CrudOperationBindable , mysql_xdevapi\CrudOperationLimitable , mysql_xdevapi\CrudOperationSortable Methods  public mysql_xdevapi\CollectionFind mysql_xdevapi\CollectionFind::bind(array placeholder_values);
  public mysql_xdevapi\DocResult mysql_xdevapi\CollectionFind::execute();
  public mysql_xdevapi\CollectionFind mysql_xdevapi\CollectionFind::fields(string projection);
  public mysql_xdevapi\CollectionFind mysql_xdevapi\CollectionFind::groupBy(string sort_expr);
  public mysql_xdevapi\CollectionFind mysql_xdevapi\CollectionFind::having(string sort_expr);
  public mysql_xdevapi\CollectionFind mysql_xdevapi\CollectionFind::limit(integer rows);
  public mysql_xdevapi\CollectionFind mysql_xdevapi\CollectionFind::lockExclusive(integer lock_waiting_option);
  public mysql_xdevapi\CollectionFind mysql_xdevapi\CollectionFind::lockShared(integer lock_waiting_option);
  public mysql_xdevapi\CollectionFind mysql_xdevapi\CollectionFind::offset(integer position);
  public mysql_xdevapi\CollectionFind mysql_xdevapi\CollectionFind::sort(string sort_expr);
}

5.8.1 CollectionFind::bind

Copyright 1997-2018 the PHP Documentation Group.

  • CollectionFind::bind

    Bind value to query placeholder

Description

public mysql_xdevapi\CollectionFind mysql_xdevapi\CollectionFind::bind(array placeholder_values);

It allows the user to bind a parameter to the placeholder in the search condition of the find operation. The placeholder has the form of :NAME where ':' is a common prefix that must always exists before any NAME, NAME is the actual name of the placeholder. The bind function accepts a list of placeholders if multiple entities have to be substituted in the search condition.

Parameters

placeholder_values

The values of the placeholder to substitute in the search condition, multiple values are allowed and have to be passed as an array of mappings PLACEHOLDER_NAME->PLACEHOLDER_VALUE, for more details see the examples.

Return Values

A CollectionFind that can be used for further processing.

Examples

Example 5.25 mysql_xdevapi\CollectionFind::bind example


<?php

//Assuming $coll is a valid collection

//In this example we're binding :job and :age to 'Programmatore' and 20.
$res = $coll->find('job like :job and age > :age');
$res = $res->bind(['job' => 'Programmatore', 'age' => 20])->execute();
//At this point $res will contain the Result object

?>


5.8.2 CollectionFind::__construct

Copyright 1997-2018 the PHP Documentation Group.

  • CollectionFind::__construct

    CollectionFind constructor

Description

private mysql_xdevapi\CollectionFind::__construct();

Warning

This function is currently not documented; only its argument list is available.

Parameters

This function has no parameters.

Examples

Example 5.26 mysql_xdevapi\CollectionFind::__construct example


<?php

/* ... */

?>


5.8.3 CollectionFind::execute

Copyright 1997-2018 the PHP Documentation Group.

  • CollectionFind::execute

    Execute the statement

Description

public mysql_xdevapi\DocResult mysql_xdevapi\CollectionFind::execute();

The execute function needs to be invoked in order to trigger the client to send the CRUD operation request to the server.

Parameters

This function has no parameters.

Return Values

A DocResult object that can be used to query the status of the operation

Examples

Example 5.27 mysql_xdevapi\CollectionFind::execute example


<?php

//Assuming $coll is a valid Collection object

//Search the collection for all the documents for which the field
//'name' is either "Marco" or "Lucio"
$res = $coll->find('name IN ("Marco","Lucio")')->execute();

?>


5.8.4 CollectionFind::fields

Copyright 1997-2018 the PHP Documentation Group.

  • CollectionFind::fields

    Set document field filter

Description

public mysql_xdevapi\CollectionFind mysql_xdevapi\CollectionFind::fields(string projection);

This is the equivalent of the SQL projection, which allows to select which columns the query shall return.

Parameters

projection

Can either be a single string or an array of string, those strings are identifying the columns that have to be returned for each document that match the search condition.

Return Values

A CollectionFind object that can be used for further processing

Examples

Example 5.28 mysql_xdevapi\CollectionFind::fields example


<?php

//Assuming $coll is a valid collection object

/*
   The following find call will search for all the documents
   with a 'job' like 'tassinaro' and will return only the column
   'age' from each document
*/
$res = $coll->find('job like \'tassinaro\'')->fields('age')->execute();

//Example which make use of the COUNT function
	$res = $coll->find()->fields(['COUNT(name) as cn', 'MAX(age) as ma', 'job as j'])->execute();
	

?>


5.8.5 CollectionFind::groupBy

Copyright 1997-2018 the PHP Documentation Group.

  • CollectionFind::groupBy

    Set grouping criteria

Description

public mysql_xdevapi\CollectionFind mysql_xdevapi\CollectionFind::groupBy(string sort_expr);

This function can be used to group the result-set by one more columns, frequently this is used with aggregate functions like COUNT,MAX,MIN,SUM etc.

Parameters

sort_expr

The columns or columns that have to be used for the group operation, this can either be a single string or an array of string arguments, one for each column.

Return Values

A CollectionFind that can be used for further processing

Examples

Example 5.29 mysql_xdevapi\CollectionFind::groupBy example


<?php

//Assuming $coll is a valid Collection object

//Extract all the documents from the Collection and group the results by the 'name' field
$res = $coll->find()->groupBy('name')->execute();

?>


5.8.6 CollectionFind::having

Copyright 1997-2018 the PHP Documentation Group.

  • CollectionFind::having

    Set condition for aggregate functions

Description

public mysql_xdevapi\CollectionFind mysql_xdevapi\CollectionFind::having(string sort_expr);

This function can be used after the 'field' operation in order to make a selection on the documents to extract.

Parameters

sort_expr

This must be a valid SQL expression, the use of aggreate functions is allowed

Return Values

CollectionFind object that can be used for further processing

Examples

Example 5.30 mysql_xdevapi\CollectionFind::having example


<?php

//Assuming $coll is a valid Collection object

//Find all the documents for which the 'age' is greather than 40,
//Only the columns 'name' and 'age' are returned in the Result object
$res = $coll->find()->fields(['name','age'])->having('age > 40')->execute();

?>


5.8.7 CollectionFind::limit

Copyright 1997-2018 the PHP Documentation Group.

  • CollectionFind::limit

    Limit number of returned documents

Description

public mysql_xdevapi\CollectionFind mysql_xdevapi\CollectionFind::limit(integer rows);

Limit the amount of documents returned by the 'find' option by the amount provided as argument

Parameters

rows

This is the maximum amount of documents that have to be returned by the find operation

Return Values

CollectionFind object that can be used for further processing

Examples

Example 5.31 mysql_xdevapi\CollectionFind::limit example


<?php

//Assuming $coll is a valid Collection object

//Extract only the first 10 documents from the collection
$res = $coll->find()->limit(10)->execute();

//Sort the documents on the base of the 'age' field
//and return the first two "oldest" person in the collection
$res = $coll->find()->sort('age desc')->limit(2)->execute();

?>


5.8.8 CollectionFind::lockExclusive

Copyright 1997-2018 the PHP Documentation Group.

  • CollectionFind::lockExclusive

    Execute operation with EXCLUSIVE LOCK

Description

public mysql_xdevapi\CollectionFind mysql_xdevapi\CollectionFind::lockExclusive(integer lock_waiting_option);

Lock exclusively the document, other transactions are blocked from updating the document until the document is locked While the document is locked, other transactions are blocked from updating those docs, from doing SELECT ... LOCK IN SHARE MODE, or from reading the data in certain transaction isolation levels. Consistent reads ignore any locks set on the records that exist in the read view.

This feature is directly useful with the modify() command, to avoid concurrency problems. Basically, it serializes access to a row through row locking

Parameters

lock_waiting_option

Optional waiting option. By default it is MYSQLX_LOCK_DEFAULT. Valid values are these constants:

  • MYSQLX_LOCK_DEFAULT

  • MYSQLX_LOCK_NOWAIT

  • MYSQLX_LOCK_SKIP_LOCKED

Return Values

Returns a CollectionFind object that can be used for further processing

Examples

Example 5.32 mysql_xdevapi\CollectionFind::lockExclusive example


<?php

//Assuming $coll is a valid Collection object and $session is a valid Session Object

$session->startTransaction();

//Returns all the documents with 'age' greather than 50 and attempt to lock them
$res = $col1->find("age > 50")->lockExclusive()->execute();

//... Do some operation on the document

//Complete the transaction and unlock the document
$session->commit();

?>


5.8.9 CollectionFind::lockShared

Copyright 1997-2018 the PHP Documentation Group.

  • CollectionFind::lockShared

    Execute operation with SHARED LOCK

Description

public mysql_xdevapi\CollectionFind mysql_xdevapi\CollectionFind::lockShared(integer lock_waiting_option);

Allows to share the documents between multiple transactions which are locking in shared mode.

Other sessions can read the rows, but cannot modify them until your transaction commits.

If any of these rows were changed by another transaction that has not yet committed,

your query waits until that transaction ends and then uses the latest values.

Parameters

lock_waiting_option

Optional waiting option. By default it is MYSQLX_LOCK_DEFAULT. Valid values are these constants:

  • MYSQLX_LOCK_DEFAULT

  • MYSQLX_LOCK_NOWAIT

  • MYSQLX_LOCK_SKIP_LOCKED

Return Values

A CollectionFind object that can be used for further processing

Examples

Example 5.33 mysql_xdevapi\CollectionFind::lockShared example


<?php

//Assuming $coll is a valid Collection object and $session is a valid Session Object

$session->startTransaction();

//Returns all the documents with 'age' greather than 50 and attempt to lock them
$res = $col1->find("age > 50")->lockShared()->execute();

//Read the document in shared mode ..
//...

//Complete the transaction and unlock the document
$session->commit();


?>


5.8.10 CollectionFind::offset

Copyright 1997-2018 the PHP Documentation Group.

  • CollectionFind::offset

    Skip given number of elements to be returned

Description

public mysql_xdevapi\CollectionFind mysql_xdevapi\CollectionFind::offset(integer position);

For the result set of a find operation, skip the first N elements that would be returned by the find operation. If the amount of element skipped is bigger than the size of the result set then the find operation will return an empty set.

Parameters

position

Number of elements to skip.

Return Values

CollectionFind object that can be used for further processing.

Examples

Example 5.34 mysql_xdevapi\CollectionFind::offset example


<?php

//Assuming $coll is a valid Collection object

//Find all the documents for which the 'job' field is equal to 'Programmatore', skip the first 3
$res = $coll->find('job like \'Programmatore\'')->offset(3)->execute();

?>


5.8.11 CollectionFind::sort

Copyright 1997-2018 the PHP Documentation Group.

  • CollectionFind::sort

    Set the sorting criteria

Description

public mysql_xdevapi\CollectionFind mysql_xdevapi\CollectionFind::sort(string sort_expr);

Sort the result set by the field selected in the sort_expr argument. The allowed orders are ASC (Ascending) or DESC (Descending). This operation is equivalent to the 'ORDER BY' SQL operation and it follows the same set of rules.

Parameters

sort_expr

One or more sorting expressions can be provided. The evaluation is from left to right, and each expression is separated by a comma.

Return Values

A CollectionFind object that can be used to execute the command, or to add additional operations.

Examples

Example 5.35 mysql_xdevapi\CollectionFind::sort example


<?php
//Assuming $coll is a valid Collection object.

// Find all the documents and sort them by 'age' in descending order, then sort again
// the result by 'job' in descending order and at the end by 'num' in ascending order
$res = $coll->find()->sort('age desc','job desc','num asc')->execute();

?>


5.9 CollectionModify class

Copyright 1997-2018 the PHP Documentation Group.

 mysql_xdevapi\CollectionModify {
mysql_xdevapi\CollectionModify , mysql_xdevapi\Executable , mysql_xdevapi\CrudOperationBindable , mysql_xdevapi\CrudOperationLimitable , mysql_xdevapi\CrudOperationSkippable , mysql_xdevapi\CrudOperationSortable Methods  public mysql_xdevapi\CollectionModify mysql_xdevapi\CollectionModify::arrayAppend(string collection_field,
                                                                                    string expression_or_literal);

  public mysql_xdevapi\CollectionModify mysql_xdevapi\CollectionModify::arrayInsert(string collection_field,
                                                                                    string expression_or_literal);

  public mysql_xdevapi\CollectionModify mysql_xdevapi\CollectionModify::bind(array placeholder_values);
  public mysql_xdevapi\Result mysql_xdevapi\CollectionModify::execute();
  public mysql_xdevapi\CollectionModify mysql_xdevapi\CollectionModify::limit(integer rows);
  public mysql_xdevapi\CollectionModify mysql_xdevapi\CollectionModify::patch(string document);
  public mysql_xdevapi\CollectionModify mysql_xdevapi\CollectionModify::replace(string collection_field,
                                                                                string expression_or_literal);

  public mysql_xdevapi\CollectionModify mysql_xdevapi\CollectionModify::set(string collection_field,
                                                                            string expression_or_literal);

  public mysql_xdevapi\CollectionModify mysql_xdevapi\CollectionModify::skip(integer position);
  public mysql_xdevapi\CollectionModify mysql_xdevapi\CollectionModify::sort(string sort_expr);
  public mysql_xdevapi\CollectionModify mysql_xdevapi\CollectionModify::unset(array fields);
}

5.9.1 CollectionModify::arrayAppend

Copyright 1997-2018 the PHP Documentation Group.

  • CollectionModify::arrayAppend

    Append element to an array field

Description

public mysql_xdevapi\CollectionModify mysql_xdevapi\CollectionModify::arrayAppend(string collection_field,
                                                                                  string expression_or_literal);

Add an element to a document's field, as multiple elements of a field are represented as an array. Unlike arrayInsert(), arrayAppend() always appends the new element at the end of the array, whereas arrayInsert() can define the location.

Parameters

collection_field

The identifier of the field where the new element is inserted.

expression_or_literal

The new element to insert at the end of the document field array.

Return Values

A CollectionModify object that can be used to execute the command, or to add additional operations.

Examples

Example 5.36 mysql_xdevapi\CollectionModify::arrayAppend example


<?php

// Assuming $coll is a valid Collection object

// For each document with a `job` like Programmatore or Cantante, add an additional
// job: 'Volontario'
$coll->modify("job in ('Programmatore', 'Cantante')")->arrayAppend('job', 'Volontario')->execute();

?>


5.9.2 CollectionModify::arrayInsert

Copyright 1997-2018 the PHP Documentation Group.

  • CollectionModify::arrayInsert

    Insert element into an array field

Description

public mysql_xdevapi\CollectionModify mysql_xdevapi\CollectionModify::arrayInsert(string collection_field,
                                                                                  string expression_or_literal);

Add an element to a document's field, as multiple elements of a field are represented as an array. Unlike arrayAppend(), arrayInsert() allows you to specify where the new element is inserted by defining which item it is after, whereas arrayAppend() always appends the new element at the end of the array.

Parameters

collection_field

Identify the item in the array that the new element is inserted after. The format of this parameter is FIELD_NAME[ INDEX ] where FIELD_NAME is the name of the document field to remove the element from, and INDEX is the INDEX of the element within the field.

The INDEX field is zero based, so the leftmost item from the array has an index of 0.

expression_or_literal

The new element to insert after FIELD_NAME[ INDEX ]

Return Values

A CollectionModify object that can be used to execute the command, or to add additional operations

Examples

Example 5.37 mysql_xdevapi\CollectionModify::arrayInsert example


<?php
// Assuming that $coll is a valid Collection object

// Add a new job 'Calciatore' after the second element in jobs
$coll->modify("name like 'Paolo'")->arrayInsert('job[1]', 'Calciatore')->execute();

?>


5.9.3 CollectionModify::bind

Copyright 1997-2018 the PHP Documentation Group.

  • CollectionModify::bind

    Bind value to query placeholder

Description

public mysql_xdevapi\CollectionModify mysql_xdevapi\CollectionModify::bind(array placeholder_values);

Bind a parameter to the placeholder in the search condition of the modify operation.

The placeholder has the form of :NAME where ':' is a common prefix that must always exists before any NAME where NAME is the name of the placeholder. The bind method accepts a list of placeholders if multiple entities have to be substituted in the search condition of the modify operation.

Parameters

placeholder_values

Placeholder values to substitute in the search condition. Multiple values are allowed and have to be passed as an array of mappings PLACEHOLDER_NAME->PLACEHOLDER_VALUE.

Return Values

A CollectionModify object that can be used to execute the command, or to add additional operations.

Examples

Example 5.38 mysql_xdevapi\CollectionModify::bind example


<?php
// Assuming $coll is a valid Collection object

// Add a new job to the document which field name is equal to 'Sakila'
$coll->modify('name like :param')->set("job", "Unemployed")->bind(['param' => 'Sakila'])->execute();

?>


5.9.4 CollectionModify::__construct

Copyright 1997-2018 the PHP Documentation Group.

  • CollectionModify::__construct

    CollectionModify constructor

Description

private mysql_xdevapi\CollectionModify::__construct();

Warning

This function is currently not documented; only its argument list is available.

Parameters

This function has no parameters.

Examples

Example 5.39 mysql_xdevapi\CollectionModify::__construct example


<?php

/* ... */

?>


5.9.5 CollectionModify::execute

Copyright 1997-2018 the PHP Documentation Group.

  • CollectionModify::execute

    Execute modify operation

Description

public mysql_xdevapi\Result mysql_xdevapi\CollectionModify::execute();

The execute method is required to send the CRUD operation request to the MySQL server.

Parameters

This function has no parameters.

Return Values

A Result object that can be used to verify the status of the operation, such as the number of affected rows.

Examples

Example 5.40 mysql_xdevapi\CollectionModify::execute example


<?php

/* ... */

?>


5.9.6 CollectionModify::limit

Copyright 1997-2018 the PHP Documentation Group.

  • CollectionModify::limit

    Limit number of modified documents

Description

public mysql_xdevapi\CollectionModify mysql_xdevapi\CollectionModify::limit(integer rows);

Limit the number of documents modified by this operation.

Parameters

rows

The maximum number of modified documents.

Return Values

A CollectionModify object.

Examples

Example 5.41 mysql_xdevapi\CollectionModify::limit example


<?php

$res = $coll->modify(2)->sort('name desc', 'age asc')->limit(4)->set('Married', 'NO')->execute();

?>


5.9.7 CollectionModify::patch

Copyright 1997-2018 the PHP Documentation Group.

  • CollectionModify::patch

    Patch document

Description

public mysql_xdevapi\CollectionModify mysql_xdevapi\CollectionModify::patch(string document);

Takes a patch object and applies it on one or more documents, and can update multiple document properties.

Warning

This function is currently not documented; only its argument list is available.

Parameters

document

A document with the properties to apply to the matching documents.

Return Values

A CollectionModify object.

Examples

Example 5.42 mysql_xdevapi\CollectionModify::patch example


<?php

$res = $coll->modify('"Programmatore" IN job')->patch('{"Hobby" : "Programmare"}')->execute();

?>


5.9.8 CollectionModify::replace

Copyright 1997-2018 the PHP Documentation Group.

  • CollectionModify::replace

    Replace document field

Description

public mysql_xdevapi\CollectionModify mysql_xdevapi\CollectionModify::replace(string collection_field,
                                                                              string expression_or_literal);

Replace (update) a given field value with a new one.

Warning

This function is currently not documented; only its argument list is available.

Parameters

collection_field

The document path of the item to set.

expression_or_literal

The value to set on the specified attribute.

Return Values

A CollectionModify object.

Examples

Example 5.43 mysql_xdevapi\CollectionModify::replace example


<?php

$res = $data = $obj->sort(['_id desc'])->limit(2)->replace('job', 'Disoccupato')->execute();

?>


5.9.9 CollectionModify::set

Copyright 1997-2018 the PHP Documentation Group.

  • CollectionModify::set

    Set document attribute

Description

public mysql_xdevapi\CollectionModify mysql_xdevapi\CollectionModify::set(string collection_field,
                                                                          string expression_or_literal);

Sets or updates attributes on documents in a collection.

Warning

This function is currently not documented; only its argument list is available.

Parameters

collection_field

The document path of the item to set.

expression_or_literal

The value to set on the specified attribute.

Return Values

A CollectionModify object.

Examples

Example 5.44 mysql_xdevapi\CollectionModify::set example


<?php

$res = $coll->modify('name like :param')->set("job", "Unemployed")->bind(['param' => 'Sakila'])->execute();

?>


5.9.10 CollectionModify::skip

Copyright 1997-2018 the PHP Documentation Group.

  • CollectionModify::skip

    Skip elements

Description

public mysql_xdevapi\CollectionModify mysql_xdevapi\CollectionModify::skip(integer position);

Skip the first N elements that would otherwise be returned by a find operation. If the number of elements skipped is larger than the size of the result set, then the find operation returns an empty set.

Warning

This function is currently not documented; only its argument list is available.

Parameters

position

Number of elements to skip.

Return Values

A CollectionModify object to use for further processing.

Examples

Example 5.45 mysql_xdevapi\CollectionModify::skip example


<?php

$coll->modify('age > :age')->sort('age desc')->unset(['age'])->bind(['age' => 20])->limit(4)->skip(1)->execute();

?>


5.9.11 CollectionModify::sort

Copyright 1997-2018 the PHP Documentation Group.

  • CollectionModify::sort

    Set the sorting criteria

Description

public mysql_xdevapi\CollectionModify mysql_xdevapi\CollectionModify::sort(string sort_expr);

Sort the result set by the field selected in the sort_expr argument. The allowed orders are ASC (Ascending) or DESC (Descending). This operation is equivalent to the 'ORDER BY' SQL operation and it follows the same set of rules.

Warning

This function is currently not documented; only its argument list is available.

Parameters

sort_expr

One or more sorting expression can be provided, the evaluation of these will be from the leftmost to the rightmost, each expression must be separated by a comma.

Return Values

CollectionModify object that can be used for further processing.

Examples

Example 5.46 mysql_xdevapi\CollectionModify::sort example


<?php

$res = $coll->modify('true')->sort('name desc', 'age asc')->limit(4)->set('Married', 'NO')->execute();

?>


5.9.12 CollectionModify::unset

Copyright 1997-2018 the PHP Documentation Group.

  • CollectionModify::unset

    Unset the value of document fields

Description

public mysql_xdevapi\CollectionModify mysql_xdevapi\CollectionModify::unset(array fields);

Removes attributes from documents in a collection.

Warning

This function is currently not documented; only its argument list is available.

Parameters

fields

The attributes to remove from documents in a collection.

Return Values

CollectionModify object that can be used for further processing.

Examples

Example 5.47 mysql_xdevapi\CollectionModify::unset example


<?php

$res = $coll->modify('job like :job_name')->unset(["age", "name"])->bind(['job_name' => 'Plumber'])->execute();

?>


5.10 CollectionRemove class

Copyright 1997-2018 the PHP Documentation Group.

 mysql_xdevapi\CollectionRemove {
mysql_xdevapi\CollectionRemove , mysql_xdevapi\Executable , mysql_xdevapi\CrudOperationBindable , mysql_xdevapi\CrudOperationLimitable , mysql_xdevapi\CrudOperationSortable Methods  public mysql_xdevapi\CollectionRemove mysql_xdevapi\CollectionRemove::bind(array placeholder_values);
  public mysql_xdevapi\Result mysql_xdevapi\CollectionRemove::execute();
  public mysql_xdevapi\CollectionRemove mysql_xdevapi\CollectionRemove::limit(integer rows);
  public mysql_xdevapi\CollectionRemove mysql_xdevapi\CollectionRemove::sort(string sort_expr);
}

5.10.1 CollectionRemove::bind

Copyright 1997-2018 the PHP Documentation Group.

  • CollectionRemove::bind

    Bind value to placeholder

Description

public mysql_xdevapi\CollectionRemove mysql_xdevapi\CollectionRemove::bind(array placeholder_values);

Bind a parameter to the placeholder in the search condition of the remove operation.

The placeholder has the form of :NAME where ':' is a common prefix that must always exists before any NAME where NAME is the name of the placeholder. The bind method accepts a list of placeholders if multiple entities have to be substituted in the search condition of the remove operation.

Warning

This function is currently not documented; only its argument list is available.

Parameters

placeholder_values

Placeholder values to substitute in the search condition. Multiple values are allowed and have to be passed as an array of mappings PLACEHOLDER_NAME->PLACEHOLDER_VALUE.

Return Values

A CollectionRemove object that can be used to execute the command, or to add additional operations.

Examples

Example 5.48 mysql_xdevapi\CollectionRemove::bind example


<?php

$res = $coll->remove('age > :age_from and age < :age_to')->bind(['age_from' => 20, 'age_to' => 50])->limit(7)->execute();

?>


5.10.2 CollectionRemove::__construct

Copyright 1997-2018 the PHP Documentation Group.

  • CollectionRemove::__construct

    CollectionRemove constructor

Description

private mysql_xdevapi\CollectionRemove::__construct();

Warning

This function is currently not documented; only its argument list is available.

Parameters

This function has no parameters.

Examples

Example 5.49 mysql_xdevapi\CollectionRemove::__construct example


<?php

/* ... */

?>


5.10.3 CollectionRemove::execute

Copyright 1997-2018 the PHP Documentation Group.

  • CollectionRemove::execute

    Execute remove operation

Description

public mysql_xdevapi\Result mysql_xdevapi\CollectionRemove::execute();

The execute function needs to be invoked in order to trigger the client to send the CRUD operation request to the server.

Warning

This function is currently not documented; only its argument list is available.

Parameters

This function has no parameters.

Return Values

Result object.

Examples

Example 5.50 mysql_xdevapi\CollectionRemove::execute example


<?php

$res = $coll->remove('true')->sort('age desc')->limit(2)->execute();

?>


5.10.4 CollectionRemove::limit

Copyright 1997-2018 the PHP Documentation Group.

  • CollectionRemove::limit

    Limit number of documents to remove

Description

public mysql_xdevapi\CollectionRemove mysql_xdevapi\CollectionRemove::limit(integer rows);

Sets the maximum number of documents to remove.

Warning

This function is currently not documented; only its argument list is available.

Parameters

rows

The maximum number of documents to remove.

Return Values

Returns a CollectionRemove object that can be used to execute the command, or to add additional operations.

Examples

Example 5.51 mysql_xdevapi\CollectionRemove::limit example


<?php

$res = $coll->remove('job in (\'Barista\', \'Programmatore\', \'Ballerino\', \'Programmatrice\')')->limit(5)->sort(['age desc', 'name asc'])->execute();

?>


5.10.5 CollectionRemove::sort

Copyright 1997-2018 the PHP Documentation Group.

  • CollectionRemove::sort

    Set the sorting criteria

Description

public mysql_xdevapi\CollectionRemove mysql_xdevapi\CollectionRemove::sort(string sort_expr);

Sort the result set by the field selected in the sort_expr argument. The allowed orders are ASC (Ascending) or DESC (Descending). This operation is equivalent to the 'ORDER BY' SQL operation and it follows the same set of rules.

Warning

This function is currently not documented; only its argument list is available.

Parameters

sort_expr

One or more sorting expressions can be provided. The evaluation is from left to right, and each expression is separated by a comma.

Return Values

A CollectionRemove object that can be used to execute the command, or to add additional operations.

Examples

Example 5.52 mysql_xdevapi\CollectionRemove::sort example


<?php

$res = $coll->remove('true')->sort('age desc')->limit(2)->execute();

?>


5.11 ColumnResult class

Copyright 1997-2018 the PHP Documentation Group.

 mysql_xdevapi\ColumnResult {
mysql_xdevapi\ColumnResult Methods  public string mysql_xdevapi\ColumnResult::getCharacterSetName();
  public string mysql_xdevapi\ColumnResult::getCollationName();
  public string mysql_xdevapi\ColumnResult::getColumnLabel();
  public string mysql_xdevapi\ColumnResult::getColumnName();
  public integer mysql_xdevapi\ColumnResult::getFractionalDigits();
  public integer mysql_xdevapi\ColumnResult::getLength();
  public string mysql_xdevapi\ColumnResult::getSchemaName();
  public string mysql_xdevapi\ColumnResult::getTableLabel();
  public string mysql_xdevapi\ColumnResult::getTableName();
  public integer mysql_xdevapi\ColumnResult::getType();
  public integer mysql_xdevapi\ColumnResult::isNumberSigned();
  public integer mysql_xdevapi\ColumnResult::isPadded();
}

5.11.1 ColumnResult::__construct

Copyright 1997-2018 the PHP Documentation Group.

  • ColumnResult::__construct

    ColumnResult constructor

Description

private mysql_xdevapi\ColumnResult::__construct();

Warning

This function is currently not documented; only its argument list is available.

Parameters

This function has no parameters.

Examples

Example 5.53 mysql_xdevapi\ColumnResult::__construct example


<?php

/* ... */

?>


5.11.2 ColumnResult::getCharacterSetName

Copyright 1997-2018 the PHP Documentation Group.

  • ColumnResult::getCharacterSetName

    Get character set

Description

public string mysql_xdevapi\ColumnResult::getCharacterSetName();

Warning

This function is currently not documented; only its argument list is available.

Parameters

This function has no parameters.

Return Values

Examples

Example 5.54 mysql_xdevapi\ColumnResult::getCharacterSetName example


<?php

/* ... */

?>


5.11.3 ColumnResult::getCollationName

Copyright 1997-2018 the PHP Documentation Group.

  • ColumnResult::getCollationName

    Get collation name

Description

public string mysql_xdevapi\ColumnResult::getCollationName();

Warning

This function is currently not documented; only its argument list is available.

Parameters

This function has no parameters.

Return Values

Examples

Example 5.55 mysql_xdevapi\ColumnResult::getCollationName example


<?php

/* ... */

?>


5.11.4 ColumnResult::getColumnLabel

Copyright 1997-2018 the PHP Documentation Group.

  • ColumnResult::getColumnLabel

    Get column label

Description

public string mysql_xdevapi\ColumnResult::getColumnLabel();

Warning

This function is currently not documented; only its argument list is available.

Parameters

This function has no parameters.

Return Values

Examples

Example 5.56 mysql_xdevapi\ColumnResult::getColumnLabel example


<?php

/* ... */

?>


5.11.5 ColumnResult::getColumnName

Copyright 1997-2018 the PHP Documentation Group.

  • ColumnResult::getColumnName

    Get column name

Description

public string mysql_xdevapi\ColumnResult::getColumnName();

Warning

This function is currently not documented; only its argument list is available.

Parameters

This function has no parameters.

Return Values

Examples

Example 5.57 mysql_xdevapi\ColumnResult::getColumnName example


<?php

/* ... */

?>


5.11.6 ColumnResult::getFractionalDigits

Copyright 1997-2018 the PHP Documentation Group.

  • ColumnResult::getFractionalDigits

    Get fractional digit length

Description

public integer mysql_xdevapi\ColumnResult::getFractionalDigits();

Fetch the number of fractional digits for column.

Warning

This function is currently not documented; only its argument list is available.

Parameters

This function has no parameters.

Return Values

Examples

Example 5.58 mysql_xdevapi\ColumnResult::getFractionalDigits example


<?php

/* ... */

?>


5.11.7 ColumnResult::getLength

Copyright 1997-2018 the PHP Documentation Group.

  • ColumnResult::getLength

    Get column field length

Description

public integer mysql_xdevapi\ColumnResult::getLength();

Warning

This function is currently not documented; only its argument list is available.

Parameters

This function has no parameters.

Return Values

Examples

Example 5.59 mysql_xdevapi\ColumnResult::getLength example


<?php

/* ... */

?>


5.11.8 ColumnResult::getSchemaName

Copyright 1997-2018 the PHP Documentation Group.

  • ColumnResult::getSchemaName

    Get schema name

Description

public string mysql_xdevapi\ColumnResult::getSchemaName();

Fetch the schema name where the column is stored.

Warning

This function is currently not documented; only its argument list is available.

Parameters

This function has no parameters.

Return Values

Examples

Example 5.60 mysql_xdevapi\ColumnResult::getSchemaName example


<?php

/* ... */

?>


5.11.9 ColumnResult::getTableLabel

Copyright 1997-2018 the PHP Documentation Group.

  • ColumnResult::getTableLabel

    Get table label

Description

public string mysql_xdevapi\ColumnResult::getTableLabel();

Warning

This function is currently not documented; only its argument list is available.

Parameters

This function has no parameters.

Return Values

Examples

Example 5.61 mysql_xdevapi\ColumnResult::getTableLabel example


<?php

/* ... */

?>


5.11.10 ColumnResult::getTableName

Copyright 1997-2018 the PHP Documentation Group.

  • ColumnResult::getTableName

    Get table name

Description

public string mysql_xdevapi\ColumnResult::getTableName();

Warning

This function is currently not documented; only its argument list is available.

Parameters

This function has no parameters.

Return Values

Name of the table for the column.

Examples

Example 5.62 mysql_xdevapi\ColumnResult::getTableName example


<?php

/* ... */

?>


5.11.11 ColumnResult::getType

Copyright 1997-2018 the PHP Documentation Group.

  • ColumnResult::getType

    Get column type

Description

public integer mysql_xdevapi\ColumnResult::getType();

Warning

This function is currently not documented; only its argument list is available.

Parameters

This function has no parameters.

Return Values

Examples

Example 5.63 mysql_xdevapi\ColumnResult::getType example


<?php

/* ... */

?>


5.11.12 ColumnResult::isNumberSigned

Copyright 1997-2018 the PHP Documentation Group.

  • ColumnResult::isNumberSigned

    Check if signed type

Description

public integer mysql_xdevapi\ColumnResult::isNumberSigned();

Warning

This function is currently not documented; only its argument list is available.

Parameters

This function has no parameters.

Return Values

TRUE if a given column as a signed type.

Examples

Example 5.64 mysql_xdevapi\ColumnResult::isNumberSigned example


<?php

/* ... */

?>


5.11.13 ColumnResult::isPadded

Copyright 1997-2018 the PHP Documentation Group.

  • ColumnResult::isPadded

    Check if padded

Description

public integer mysql_xdevapi\ColumnResult::isPadded();

Warning

This function is currently not documented; only its argument list is available.

Parameters

This function has no parameters.

Return Values

TRUE if a given column is padded.

Examples

Example 5.65 mysql_xdevapi\ColumnResult::isPadded example


<?php

/* ... */

?>


5.12 CrudOperationBindable interface

Copyright 1997-2018 the PHP Documentation Group.

 mysql_xdevapi\CrudOperationBindable {
mysql_xdevapi\CrudOperationBindable Methods  abstract public mysql_xdevapi\CrudOperationBindable mysql_xdevapi\CrudOperationBindable::bind(array placeholder_values);
}

5.12.1 CrudOperationBindable::bind

Copyright 1997-2018 the PHP Documentation Group.

  • CrudOperationBindable::bind

    Bind value to placeholder

Description

abstract public mysql_xdevapi\CrudOperationBindable mysql_xdevapi\CrudOperationBindable::bind(array placeholder_values);

Binds a value to a specific placeholder.

Warning

This function is currently not documented; only its argument list is available.

Parameters

placeholder_values

The name of the placeholders and the values to bind.

Return Values

A CrudOperationBindable object.

Examples

Example 5.66 mysql_xdevapi\CrudOperationBindable::bind example


<?php

$res = $coll->modify('name like :name')->arrayInsert('job[0]', 'Calciatore')->bind(['name' => 'ENTITY'])->execute();
$res = $table->delete()->orderby('age desc')->where('age < 20 and age > 12 and name != :name')->bind(['name' => 'Tierney'])->limit(2)->execute();

?>


5.13 CrudOperationLimitable interface

Copyright 1997-2018 the PHP Documentation Group.

 mysql_xdevapi\CrudOperationLimitable {
mysql_xdevapi\CrudOperationLimitable Methods  abstract public mysql_xdevapi\CrudOperationLimitable mysql_xdevapi\CrudOperationLimitable::limit(integer rows);
}

5.13.1 CrudOperationLimitable::limit

Copyright 1997-2018 the PHP Documentation Group.

  • CrudOperationLimitable::limit

    Set result limit

Description

abstract public mysql_xdevapi\CrudOperationLimitable mysql_xdevapi\CrudOperationLimitable::limit(integer rows);

Sets the maximum number of records or documents to return.

Warning

This function is currently not documented; only its argument list is available.

Parameters

rows

The maximum number of records or documents.

Return Values

A CrudOperationLimitable object.

Examples

Example 5.67 mysql_xdevapi\CrudOperationLimitable::limit example


<?php

$res = $coll->find()->fields(['name as n','age as a','job as j'])->groupBy('j')->limit(11)->execute();
$res = $table->update()->set('age',69)->where('age > 15 and age < 22')->limit(4)->orderby(['age asc','name desc'])->execute();

?>


5.14 CrudOperationSkippable interface

Copyright 1997-2018 the PHP Documentation Group.

 mysql_xdevapi\CrudOperationSkippable {
mysql_xdevapi\CrudOperationSkippable Methods  abstract public mysql_xdevapi\CrudOperationSkippable mysql_xdevapi\CrudOperationSkippable::skip(integer skip);
}

5.14.1 CrudOperationSkippable::skip

Copyright 1997-2018 the PHP Documentation Group.

  • CrudOperationSkippable::skip

    Number of operations to skip

Description

abstract public mysql_xdevapi\CrudOperationSkippable mysql_xdevapi\CrudOperationSkippable::skip(integer skip);

Skip this number of records in the returned operation.

Warning

This function is currently not documented; only its argument list is available.

Parameters

skip

Number of elements to skip.

Return Values

A CrudOperationSkippable object.

Examples

Example 5.68 mysql_xdevapi\CrudOperationSkippable::skip example


<?php

$res = $coll->find('job like \'Programmatore\'')->limit(1)->skip(3)->sort('age asc')->execute();

?>


5.15 CrudOperationSortable interface

Copyright 1997-2018 the PHP Documentation Group.

 mysql_xdevapi\CrudOperationSortable {
mysql_xdevapi\CrudOperationSortable Methods  abstract public mysql_xdevapi\CrudOperationSortable mysql_xdevapi\CrudOperationSortable::sort(string sort_expr);
}

5.15.1 CrudOperationSortable::sort

Copyright 1997-2018 the PHP Documentation Group.

  • CrudOperationSortable::sort

    Sort results

Description

abstract public mysql_xdevapi\CrudOperationSortable mysql_xdevapi\CrudOperationSortable::sort(string sort_expr);

Sort the result set by the field selected in the sort_expr argument. The allowed orders are ASC (Ascending) or DESC (Descending). This operation is equivalent to the 'ORDER BY' SQL operation and it follows the same set of rules.

Warning

This function is currently not documented; only its argument list is available.

Parameters

sort_expr

One or more sorting expressions can be provided. The evaluation is from left to right, and each expression is separated by a comma.

Return Values

A CrudOperationSortable object.

Examples

Example 5.69 mysql_xdevapi\CrudOperationSortable::sort example


<?php

$res = $coll->find('job like \'Cavia\'')->sort('age desc', '_id desc')->execute();

?>


5.16 DatabaseObject interface

Copyright 1997-2018 the PHP Documentation Group.

 mysql_xdevapi\DatabaseObject {
mysql_xdevapi\DatabaseObject Methods  abstract public bool mysql_xdevapi\DatabaseObject::existsInDatabase();
  abstract public string mysql_xdevapi\DatabaseObject::getName();
  abstract public mysql_xdevapi\Session mysql_xdevapi\DatabaseObject::getSession();
}

5.16.1 DatabaseObject::existsInDatabase

Copyright 1997-2018 the PHP Documentation Group.

  • DatabaseObject::existsInDatabase

    Check if object exists in database

Description

abstract public bool mysql_xdevapi\DatabaseObject::existsInDatabase();

Verifies if the database object refers to an object that exists in the database.

Parameters

This function has no parameters.

Return Values

Returns TRUE if object exists in the database, else FALSE if it does not.

Examples

Example 5.70 mysql_xdevapi\DatabaseObject::existsInDatabase example


<?php

$existInDb = $dbObj->existsInDatabase();

?>


5.16.2 DatabaseObject::getName

Copyright 1997-2018 the PHP Documentation Group.

  • DatabaseObject::getName

    Get object name

Description

abstract public string mysql_xdevapi\DatabaseObject::getName();

Fetch name of this database object.

Warning

This function is currently not documented; only its argument list is available.

Parameters

This function has no parameters.

Return Values

The name of this database object.

Examples

Example 5.71 mysql_xdevapi\DatabaseObject::getName example


<?php

$dbObjName = $dbObj->getName();

?>


5.16.3 DatabaseObject::getSession

Copyright 1997-2018 the PHP Documentation Group.

  • DatabaseObject::getSession

    Get session name

Description

abstract public mysql_xdevapi\Session mysql_xdevapi\DatabaseObject::getSession();

Fetch session associated to the database object.

Warning

This function is currently not documented; only its argument list is available.

Parameters

This function has no parameters.

Return Values

The Session object.

Examples

Example 5.72 mysql_xdevapi\DatabaseObject::getSession example


<?php

$session = $dbObj->getSession();

?>


5.17 DocResult class

Copyright 1997-2018 the PHP Documentation Group.

 mysql_xdevapi\DocResult {
mysql_xdevapi\DocResult , mysql_xdevapi\BaseResult , Traversable Methods  public Array mysql_xdevapi\DocResult::fetchAll();
  public Object mysql_xdevapi\DocResult::fetchOne();
  public Array mysql_xdevapi\DocResult::getWarnings();
  public integer mysql_xdevapi\DocResult::getWarningsCount();
}

5.17.1 DocResult::__construct

Copyright 1997-2018 the PHP Documentation Group.

  • DocResult::__construct

    DocResult constructor

Description

private mysql_xdevapi\DocResult::__construct();

Warning

This function is currently not documented; only its argument list is available.

Parameters

This function has no parameters.

Examples

Example 5.73 mysql_xdevapi\DocResult::__construct example


<?php

/* ... */

?>


5.17.2 DocResult::fetchAll

Copyright 1997-2018 the PHP Documentation Group.

  • DocResult::fetchAll

    Get all rows

Description

public Array mysql_xdevapi\DocResult::fetchAll();

Warning

This function is currently not documented; only its argument list is available.

Parameters

This function has no parameters.

Return Values

An array of Result objects from the last operation on the collection.

Examples

Example 5.74 mysql_xdevapi\DocResult::fetchAll example


<?php

/* ... */

?>


5.17.3 DocResult::fetchOne

Copyright 1997-2018 the PHP Documentation Group.

  • DocResult::fetchOne

    Get one row

Description

public Object mysql_xdevapi\DocResult::fetchOne();

Warning

This function is currently not documented; only its argument list is available.

Parameters

This function has no parameters.

Return Values

A Result object from the last operation on a collection.

Examples

Example 5.75 mysql_xdevapi\DocResult::fetchOne example


<?php

/* ... */

?>


5.17.4 DocResult::getWarnings

Copyright 1997-2018 the PHP Documentation Group.

  • DocResult::getWarnings

    Get warnings from last operation

Description

public Array mysql_xdevapi\DocResult::getWarnings();

Warning

This function is currently not documented; only its argument list is available.

Parameters

This function has no parameters.

Return Values

An array of Warning objects from the last operation.

Examples

Example 5.76 mysql_xdevapi\DocResult::getWarnings example


<?php

/* ... */

?>


5.17.5 DocResult::getWarningsCount

Copyright 1997-2018 the PHP Documentation Group.

  • DocResult::getWarningsCount

    Get warning count from last operation

Description

public integer mysql_xdevapi\DocResult::getWarningsCount();

Warning

This function is currently not documented; only its argument list is available.

Parameters

This function has no parameters.

Return Values

Examples

Example 5.77 mysql_xdevapi\DocResult::getWarningsCount example


<?php

/* ... */

?>


5.18 Driver class

Copyright 1997-2018 the PHP Documentation Group.

 mysql_xdevapi\Driver {
mysql_xdevapi\Driver Constants  const string mysql_xdevapi\Driver::version = =8.0.3;
Constructor  private mysql_xdevapi\Driver::__construct();
}

mysql_xdevapi\Driver::version

5.18.1 Driver::__construct

Copyright 1997-2018 the PHP Documentation Group.

  • Driver::__construct

    Driver constructor

Description

private mysql_xdevapi\Driver::__construct();

Warning

This function is currently not documented; only its argument list is available.

Parameters

This function has no parameters.

Examples

Example 5.78 mysql_xdevapi\Driver::__construct example


<?php

/* ... */

?>


5.19 Exception class

Copyright 1997-2018 the PHP Documentation Group.

 mysql_xdevapi\Exception {
mysql_xdevapi\Exception, extends RuntimeException , Throwable }

5.20 Executable interface

Copyright 1997-2018 the PHP Documentation Group.

 mysql_xdevapi\Executable {
mysql_xdevapi\Executable Methods  abstract public mysql_xdevapi\Result mysql_xdevapi\Executable::execute();
}

5.20.1 Executable::execute

Copyright 1997-2018 the PHP Documentation Group.

  • Executable::execute

    Execute statement

Description

abstract public mysql_xdevapi\Result mysql_xdevapi\Executable::execute();

Execute the statement from either a collection operation or a table query.

Parameters

This function has no parameters.

Return Values

A Result object.

Examples

Example 5.79 mysql_xdevapi\Executable::execute example


<?php

$res = $coll->find()->execute();
$res = $table->select(['age', 'name'])->execute();

?>


5.21 ExecutionStatus class

Copyright 1997-2018 the PHP Documentation Group.

 mysql_xdevapi\ExecutionStatus {
mysql_xdevapi\ExecutionStatus Properties  public affectedItems ;
  public matchedItems ;
  public foundItems ;
  public lastInsertId ;
  public lastDocumentId ;
Constructor  private mysql_xdevapi\ExecutionStatus::__construct();
}

affectedItems

matchedItems

foundItems

lastInsertId

lastDocumentId

5.21.1 ExecutionStatus::__construct

Copyright 1997-2018 the PHP Documentation Group.

  • ExecutionStatus::__construct

    ExecutionStatus constructor

Description

private mysql_xdevapi\ExecutionStatus::__construct();

Warning

This function is currently not documented; only its argument list is available.

Parameters

This function has no parameters.

Examples

Example 5.80 mysql_xdevapi\ExecutionStatus::__construct example


<?php

/* ... */

?>


5.22 Expression class

Copyright 1997-2018 the PHP Documentation Group.

 mysql_xdevapi\Expression {
mysql_xdevapi\Expression Properties  public name ;
Constructor  public mysql_xdevapi\Expression::__construct(string expression);
}

name

5.22.1 Expression::__construct

Copyright 1997-2018 the PHP Documentation Group.

  • Expression::__construct

    Expression constructor

Description

public mysql_xdevapi\Expression::__construct(string expression);

Warning

This function is currently not documented; only its argument list is available.

Parameters

expression

Examples

Example 5.81 mysql_xdevapi\Expression::__construct example


<?php

/* ... */

?>


5.23 FieldMetadata class

Copyright 1997-2018 the PHP Documentation Group.

 mysql_xdevapi\FieldMetadata {
mysql_xdevapi\FieldMetadata Properties  public type ;
  public type_name ;
  public name ;
  public original_name ;
  public table ;
  public original_table ;
  public schema ;
  public catalog ;
  public collation ;
  public fractional_digits ;
  public length ;
  public flags ;
  public content_type ;
Constructor  private mysql_xdevapi\FieldMetadata::__construct();
}

type

type_name

name

original_name

table

original_table

schema

catalog

collation

fractional_digits

length

flags

content_type

5.23.1 FieldMetadata::__construct

Copyright 1997-2018 the PHP Documentation Group.

  • FieldMetadata::__construct

    FieldMetadata constructor

Description

private mysql_xdevapi\FieldMetadata::__construct();

Warning

This function is currently not documented; only its argument list is available.

Parameters

This function has no parameters.

Examples

Example 5.82 mysql_xdevapi\FieldMetadata::__construct example


<?php

/* ... */

?>


5.24 Result class

Copyright 1997-2018 the PHP Documentation Group.

 mysql_xdevapi\Result {
mysql_xdevapi\Result , mysql_xdevapi\BaseResult , Traversable Methods  public int mysql_xdevapi\Result::getAutoIncrementValue();
  public ArrayOfInt mysql_xdevapi\Result::getGeneratedIds();
  public array mysql_xdevapi\Result::getWarnings();
  public integer mysql_xdevapi\Result::getWarningsCount();
}

5.24.1 Result::__construct

Copyright 1997-2018 the PHP Documentation Group.

  • Result::__construct

    Result constructor

Description

private mysql_xdevapi\Result::__construct();

Warning

This function is currently not documented; only its argument list is available.

Parameters

This function has no parameters.

Examples

Example 5.83 mysql_xdevapi\Result::__construct example


<?php

/* ... */

?>


5.24.2 Result::getAutoIncrementValue

Copyright 1997-2018 the PHP Documentation Group.

  • Result::getAutoIncrementValue

    Get autoincremented value

Description

public int mysql_xdevapi\Result::getAutoIncrementValue();

Warning

This function is currently not documented; only its argument list is available.

Parameters

This function has no parameters.

Return Values

Examples

Example 5.84 mysql_xdevapi\Result::getAutoIncrementValue example


<?php

/* ... */

?>


5.24.3 Result::getGeneratedIds

Copyright 1997-2018 the PHP Documentation Group.

  • Result::getGeneratedIds

    Get generated ids

Description

public ArrayOfInt mysql_xdevapi\Result::getGeneratedIds();

Warning

This function is currently not documented; only its argument list is available.

Parameters

This function has no parameters.

Return Values

An array of generated IDs from the last operation.

Examples

Example 5.85 mysql_xdevapi\Result::getGeneratedIds example


<?php

/* ... */

?>


5.24.4 Result::getWarnings

Copyright 1997-2018 the PHP Documentation Group.

  • Result::getWarnings

    Get warnings from last operation

Description

public array mysql_xdevapi\Result::getWarnings();

Warning

This function is currently not documented; only its argument list is available.

Parameters

This function has no parameters.

Return Values

An array of Warning objects from the last operation.

Examples

Example 5.86 mysql_xdevapi\Result::getWarnings example


<?php

/* ... */

?>


5.24.5 Result::getWarningsCount

Copyright 1997-2018 the PHP Documentation Group.

  • Result::getWarningsCount

    Get warning count from last operation

Description

public integer mysql_xdevapi\Result::getWarningsCount();

Warning

This function is currently not documented; only its argument list is available.

Parameters

This function has no parameters.

Return Values

The number of warnings generated by the last operation.

Examples

Example 5.87 mysql_xdevapi\Result::getWarningsCount example


<?php

/* ... */

?>


5.25 RowResult class

Copyright 1997-2018 the PHP Documentation Group.

 mysql_xdevapi\RowResult {
mysql_xdevapi\RowResult , mysql_xdevapi\BaseResult , Traversable Methods  public array mysql_xdevapi\RowResult::fetchAll();
  public object mysql_xdevapi\RowResult::fetchOne();
  public integer mysql_xdevapi\RowResult::getColumnCount();
  public array mysql_xdevapi\RowResult::getColumnNames();
  public array mysql_xdevapi\RowResult::getColumns();
  public array mysql_xdevapi\RowResult::getWarnings();
  public integer mysql_xdevapi\RowResult::getWarningsCount();
}

5.25.1 RowResult::__construct

Copyright 1997-2018 the PHP Documentation Group.

  • RowResult::__construct

    RowResult constructor

Description

private mysql_xdevapi\RowResult::__construct();

Represents the result set obtained from querying the database.

Parameters

This function has no parameters.

Examples

Example 5.88 mysql_xdevapi\RowResult::__construct example


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

$schema = $session->getSchema("addressbook");
$table  = $schema->getTable("names");

$row = $table->select('name', 'age')->where('age > 18')->execute()->fetchAll();

print_r($row);

   

The above example will output something similar to:


Array
(
    [0] => Array
        (
            [name] => John
            [age] => 42
        )
    [1] => Array
        (
            [name] => Sam
            [age] => 33
        )
)


5.25.2 RowResult::fetchAll

Copyright 1997-2018 the PHP Documentation Group.

  • RowResult::fetchAll

    Get all rows from result

Description

public array mysql_xdevapi\RowResult::fetchAll();

Fetch all the rows from the result set.

Parameters

This function has no parameters.

Return Values

A numerical array of results, with each row as an array.

Examples

Example 5.89 mysql_xdevapi\RowResult::fetchAll example


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

$session->sql("DROP DATABASE addressbook")->execute();
$session->sql("CREATE DATABASE addressbook")->execute();
$session->sql("CREATE TABLE addressbook.names(name text, age int)")->execute();
$session->sql("INSERT INTO addressbook.names values ('John', 42), ('Sam', 33)")->execute();

$schema = $session->getSchema("addressbook");
$table  = $schema->getTable("names");

$row = $table->select('name', 'age')->execute()->fetchAll();

print_r($row);

   

The above example will output something similar to:


Array
(
    [0] => Array
        (
            [name] => John
            [age] => 42
        )
    [1] => Array
        (
            [name] => Sam
            [age] => 33
        )
)


5.25.3 RowResult::fetchOne

Copyright 1997-2018 the PHP Documentation Group.

  • RowResult::fetchOne

    Get row from result

Description

public object mysql_xdevapi\RowResult::fetchOne();

Fetch one result from the result set.

Warning

This function is currently not documented; only its argument list is available.

Parameters

This function has no parameters.

Return Values

Examples

Example 5.90 mysql_xdevapi\RowResult::fetchOne example


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

$session->sql("DROP DATABASE addressbook")->execute();
$session->sql("CREATE DATABASE addressbook")->execute();
$session->sql("CREATE TABLE addressbook.names(name text, age int)")->execute();
$session->sql("INSERT INTO addressbook.names values ('John', 42), ('Sam', 33)")->execute();

$schema = $session->getSchema("addressbook");
$table  = $schema->getTable("names");

$row = $table->select('name', 'age')->where('age < 40')->execute()->fetchOne();

print_r($row);

   

The above example will output something similar to:


Array
(
    [name] => Sam
    [age] => 33
)


5.25.4 RowResult::getColumnCount

Copyright 1997-2018 the PHP Documentation Group.

  • RowResult::getColumnCount

    Get column count

Description

public integer mysql_xdevapi\RowResult::getColumnCount();

Retrieve the column count for columns present in the result set.

Parameters

This function has no parameters.

Return Values

The number of columns, or FALSE if the result set is empty.

Examples

Example 5.91 mysql_xdevapi\RowResult::getColumnCount example


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

$session->sql("DROP DATABASE addressbook")->execute();
$session->sql("CREATE DATABASE foo")->execute();
$session->sql("CREATE TABLE foo.test_table(x int)")->execute();
$session->sql("INSERT INTO addressbook.names values ('John', 42), ('Sam', 33)")->execute();

$sql = $session->sql("SELECT * from addressbook.names")->execute();

echo $sql->getColumnCount();

   

The above example will output something similar to:


2


5.25.5 RowResult::getColumnNames

Copyright 1997-2018 the PHP Documentation Group.

  • RowResult::getColumnNames

    Get all column names

Description

public array mysql_xdevapi\RowResult::getColumnNames();

Retrieve column names for columns present in the result set.

Warning

This function is currently not documented; only its argument list is available.

Parameters

This function has no parameters.

Return Values

A numerical array of table columns names, or FALSE if the result set is empty.

Examples

Example 5.92 mysql_xdevapi\RowResult::getColumnNames example


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

$session->sql("DROP DATABASE addressbook")->execute();
$session->sql("CREATE DATABASE foo")->execute();
$session->sql("CREATE TABLE foo.test_table(x int)")->execute();
$session->sql("INSERT INTO addressbook.names values ('John', 42), ('Sam', 33)")->execute();

$sql = $session->sql("SELECT * from addressbook.names")->execute();

$colnames = $sql->getColumnNames();
  
print_r($colnames);

   

The above example will output something similar to:


Array
(
    [0] => name
    [1] => age
)


5.25.6 RowResult::getColumns

Copyright 1997-2018 the PHP Documentation Group.

  • RowResult::getColumns

    Get column metadata

Description

public array mysql_xdevapi\RowResult::getColumns();

Retrieve column metadata for columns present in the result set.

Warning

This function is currently not documented; only its argument list is available.

Parameters

This function has no parameters.

Return Values

An array of FieldMetadata objects representing the columns in the result, or FALSE if the result set is empty.

Examples

Example 5.93 mysql_xdevapi\RowResult::getColumns example


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

$session->sql("DROP DATABASE addressbook")->execute();
$session->sql("CREATE DATABASE foo")->execute();
$session->sql("CREATE TABLE foo.test_table(x int)")->execute();
$session->sql("INSERT INTO addressbook.names values ('John', 42), ('Sam', 33)")->execute();

$sql = $session->sql("SELECT * from addressbook.names")->execute();

$cols = $sql->getColumns();
  
print_r($cols);

   

The above example will output something similar to:


Array
(
    [0] => mysql_xdevapi\FieldMetadata Object
        (
            [type] => 7
            [type_name] => BYTES
            [name] => name
            [original_name] => name
            [table] => names
            [original_table] => names
            [schema] => addressbook
            [catalog] => def
            [collation] => 255
            [fractional_digits] => 0
            [length] => 65535
            [flags] => 0
            [content_type] => 0
        )
    [1] => mysql_xdevapi\FieldMetadata Object
        (
            [type] => 1
            [type_name] => SINT
            [name] => age
            [original_name] => age
            [table] => names
            [original_table] => names
            [schema] => addressbook
            [catalog] => def
            [collation] => 0
            [fractional_digits] => 0
            [length] => 11
            [flags] => 0
            [content_type] => 0
        )
)


5.25.7 RowResult::getWarnings

Copyright 1997-2018 the PHP Documentation Group.

  • RowResult::getWarnings

    Get warnings from last operation

Description

public array mysql_xdevapi\RowResult::getWarnings();

Retrieve warnings from the last RowResult operation.

Parameters

This function has no parameters.

Return Values

An array of Warning objects from the last operation. Each object defines an error 'message', error 'level', and error 'code'.

Examples

Example 5.94 mysql_xdevapi\RowResult::getWarnings example


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

$session->executeSql("CREATE DATABASE foo");
$session->executeSql("CREATE TABLE foo.test_table(x int)");

$schema = $session->getSchema("foo");
$table  = $schema->getTable("test_table");

$table->insert(['x'])->values([1])->values([2])->execute();

$res = $table->select(['x/0 as bad_x'])->execute();
$warnings = $res->getWarnings();

print_r($warnings);
?>

   

The above example will output something similar to:


Array
(
    [0] => mysql_xdevapi\Warning Object
        (
            [message] => Division by 0
            [level] => 2
            [code] => 1365
        )
    [1] => mysql_xdevapi\Warning Object
        (
            [message] => Division by 0
            [level] => 2
            [code] => 1365
        )
)


5.25.8 RowResult::getWarningsCount

Copyright 1997-2018 the PHP Documentation Group.

  • RowResult::getWarningsCount

    Get warning count from last operation

Description

public integer mysql_xdevapi\RowResult::getWarningsCount();

Retrieve the number of warnings from the last RowResult operation.

Parameters

This function has no parameters.

Return Values

The number of warnings generated by the last operation, or FALSE if the result set is empty or there are no warnings.

Examples

Example 5.95 mysql_xdevapi\RowResult::getWarningsCount example


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

$session->sql("DROP DATABASE addressbook")->execute();
$session->sql("CREATE DATABASE foo")->execute();
$session->sql("CREATE TABLE foo.test_table(x int)")->execute();

$schema = $session->getSchema("foo");
$table  = $schema->getTable("test_table");

$table->insert(['x'])->values([1])->values([2])->execute();

$res = $table->select(['x/0 as bad_x'])->execute();

echo $res->getWarningsCount();
?>

   

The above example will output something similar to:


2


5.26 Schema class

Copyright 1997-2018 the PHP Documentation Group.

 mysql_xdevapi\Schema {
mysql_xdevapi\Schema , mysql_xdevapi\DatabaseObject Properties  public name ;
Methods  public mysql_xdevapi\Collection mysql_xdevapi\Schema::createCollection(string name);
  public bool mysql_xdevapi\Schema::dropCollection(string collection_name);
  public bool mysql_xdevapi\Schema::existsInDatabase();
  public mysql_xdevapi\Collection mysql_xdevapi\Schema::getCollection(string name);
  public mysql_xdevapi\Table mysql_xdevapi\Schema::getCollectionAsTable(string name);
  public array mysql_xdevapi\Schema::getCollections();
  public string mysql_xdevapi\Schema::getName();
  public mysql_xdevapi\Session mysql_xdevapi\Schema::getSession();
  public mysql_xdevapi\Table mysql_xdevapi\Schema::getTable(string name);
  public array mysql_xdevapi\Schema::getTables();
}

name

5.26.1 Schema::__construct

Copyright 1997-2018 the PHP Documentation Group.

  • Schema::__construct

    constructor

Description

private mysql_xdevapi\Schema::__construct();

Warning

This function is currently not documented; only its argument list is available.

Parameters

This function has no parameters.

Examples

Example 5.96 mysql_xdevapi\Schema::__construct example


<?php

/* ... */

?>


5.26.2 Schema::createCollection

Copyright 1997-2018 the PHP Documentation Group.

  • Schema::createCollection

    Add collection to schema

Description

public mysql_xdevapi\Collection mysql_xdevapi\Schema::createCollection(string name);

Create a collection within the schema.

Warning

This function is currently not documented; only its argument list is available.

Parameters

name

Return Values

Examples

Example 5.97 mysql_xdevapi\Schema::createCollection example


<?php

/* ... */

?>


5.26.3 Schema::dropCollection

Copyright 1997-2018 the PHP Documentation Group.

  • Schema::dropCollection

    Drop collection from schema

Description

public bool mysql_xdevapi\Schema::dropCollection(string collection_name);

Warning

This function is currently not documented; only its argument list is available.

Parameters

collection_name

Return Values

Examples

Example 5.98 mysql_xdevapi\Schema::dropCollection example


<?php

/* ... */

?>


5.26.4 Schema::existsInDatabase

Copyright 1997-2018 the PHP Documentation Group.

  • Schema::existsInDatabase

    Check if schema exists in database

Description

public bool mysql_xdevapi\Schema::existsInDatabase();

Warning

This function is currently not documented; only its argument list is available.

Parameters

This function has no parameters.

Return Values

Examples

Example 5.99 mysql_xdevapi\Schema::existsInDatabase example


<?php

/* ... */

?>


5.26.5 Schema::getCollection

Copyright 1997-2018 the PHP Documentation Group.

  • Schema::getCollection

    Get collection from schema

Description

public mysql_xdevapi\Collection mysql_xdevapi\Schema::getCollection(string name);

Warning

This function is currently not documented; only its argument list is available.

Parameters

name

Return Values

The Collection object for the selected collection.

Examples

Example 5.100 mysql_xdevapi\Schema::getCollection example


<?php

/* ... */

?>


5.26.6 Schema::getCollectionAsTable

Copyright 1997-2018 the PHP Documentation Group.

  • Schema::getCollectionAsTable

    Get collection table object

Description

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

Warning

This function is currently not documented; only its argument list is available.

Parameters

name

Return Values

A table object for the defined table.

Examples

Example 5.101 mysql_xdevapi\Schema::getCollectionAsTable example


<?php

/* ... */

?>


5.26.7 Schema::getCollections

Copyright 1997-2018 the PHP Documentation Group.

  • Schema::getCollections

    Get all schema collections

Description

public array mysql_xdevapi\Schema::getCollections();

Fetch a list of collections for this schema.

Parameters

This function has no parameters.

Return Values

Array of all collections in this schema.

Examples

Example 5.102 mysql_xdevapi\Schema::getCollections example


<?php

$collections = $schema->getCollections();

?>


5.26.8 Schema::getName

Copyright 1997-2018 the PHP Documentation Group.

  • Schema::getName

    Get schema name

Description

public string mysql_xdevapi\Schema::getName();

Warning

This function is currently not documented; only its argument list is available.

Parameters

This function has no parameters.

Return Values

Examples

Example 5.103 mysql_xdevapi\Schema::getName example


<?php

/* ... */

?>


5.26.9 Schema::getSession

Copyright 1997-2018 the PHP Documentation Group.

  • Schema::getSession

    Get schema session

Description

public mysql_xdevapi\Session mysql_xdevapi\Schema::getSession();

Warning

This function is currently not documented; only its argument list is available.

Parameters

This function has no parameters.

Return Values

Examples

Example 5.104 mysql_xdevapi\Schema::getSession example


<?php

$session = $schema->getSession();

?>


5.26.10 Schema::getTable

Copyright 1997-2018 the PHP Documentation Group.

  • Schema::getTable

    Get schema table

Description

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

Warning

This function is currently not documented; only its argument list is available.

Parameters

name

Return Values

Examples

Example 5.105 mysql_xdevapi\Schema::getTable example


<?php

/* ... */

?>


5.26.11 Schema::getTables

Copyright 1997-2018 the PHP Documentation Group.

  • Schema::getTables

    Get schema tables

Description

public array mysql_xdevapi\Schema::getTables();

Warning

This function is currently not documented; only its argument list is available.

Parameters

This function has no parameters.

Return Values

An array of table objects.

Examples

Example 5.106 mysql_xdevapi\Schema::getTables example


<?php

/* ... */

?>


5.27 SchemaObject interface

Copyright 1997-2018 the PHP Documentation Group.

 mysql_xdevapi\SchemaObject {
mysql_xdevapi\SchemaObject , mysql_xdevapi\DatabaseObject Methods  abstract mysql_xdevapi\Schema mysql_xdevapi\SchemaObject::getSchema();
}

5.27.1 SchemaObject::getSchema

Copyright 1997-2018 the PHP Documentation Group.

  • SchemaObject::getSchema

    Get schema object

Description

abstract mysql_xdevapi\Schema mysql_xdevapi\SchemaObject::getSchema();

Warning

This function is currently not documented; only its argument list is available.

Parameters

This function has no parameters.

Return Values

The current Schema object.

Examples

Example 5.107 mysql_xdevapi\SchemaObject::getSchema example


<?php

/* ... */

?>


5.28 Session class

Copyright 1997-2018 the PHP Documentation Group.

 mysql_xdevapi\Session {
mysql_xdevapi\Session Methods  public bool mysql_xdevapi\Session::close();
  public Object mysql_xdevapi\Session::commit();
  public mysql_xdevapi\Schema mysql_xdevapi\Session::createSchema(string schema_name);
  public bool mysql_xdevapi\Session::dropSchema(string schema_name);
  public Object mysql_xdevapi\Session::executeSql(string statement);
  public string mysql_xdevapi\Session::generateUUID();
  public integer mysql_xdevapi\Session::getClientId();
  public mysql_xdevapi\Schema mysql_xdevapi\Session::getSchema(string schema_name);
  public array mysql_xdevapi\Session::getSchemas();
  public integer mysql_xdevapi\Session::getServerVersion();
  public object mysql_xdevapi\Session::killClient(integer client_id);
  public array mysql_xdevapi\Session::listClients();
  public string mysql_xdevapi\Session::quoteName(string name);
  public void mysql_xdevapi\Session::releaseSavepoint(string name);
  public void mysql_xdevapi\Session::rollback();
  public void mysql_xdevapi\Session::rollbackTo(string name);
  public string mysql_xdevapi\Session::setSavepoint(string name);
  public mysql_xdevapi\SqlStatement mysql_xdevapi\Session::sql(string query);
  public void mysql_xdevapi\Session::startTransaction();
}

5.28.1 Session::close

Copyright 1997-2018 the PHP Documentation Group.

  • Session::close

    Close session

Description

public bool mysql_xdevapi\Session::close();

Close the session with the server.

Parameters

This function has no parameters.

Return Values

TRUE if the session closed.

Examples

Example 5.108 mysql_xdevapi\Session::close example


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

$schema = $session->getSchema("addressbook");
$table  = $schema->getTable("names");

$session->close();


5.28.2 Session::commit

Copyright 1997-2018 the PHP Documentation Group.

  • Session::commit

    Commit transaction

Description

public Object mysql_xdevapi\Session::commit();

Commit the transaction.

Parameters

This function has no parameters.

Return Values

An SqlStatementResult object.

Examples

Example 5.109 mysql_xdevapi\Session::commit example


<?php
$session    = mysql_xdevapi\getSession("mysqlx://user:password@localhost");
$collection = $session->getSchema("addressbook")->getCollection("friends");

$session->startTransaction();

$collection->add('{"John":42, "Sam":33}')->execute();
$savepoint = $session->setSavepoint();

$session->commit();
$session->close();


5.28.3 Session::__construct

Copyright 1997-2018 the PHP Documentation Group.

  • Session::__construct

    Description constructor

Description

private mysql_xdevapi\Session::__construct();

A Session object, as initiated by getSession().

Parameters

This function has no parameters.

Examples

Example 5.110 mysql_xdevapi\Session::__construct example


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


5.28.4 Session::createSchema

Copyright 1997-2018 the PHP Documentation Group.

  • Session::createSchema

    Create new schema

Description

public mysql_xdevapi\Schema mysql_xdevapi\Session::createSchema(string schema_name);

Creates a new schema.

Parameters

schema_name

Name of the schema to create.

Return Values

A Schema object on success, and emits an exception on failure.

Examples

Example 5.111 mysql_xdevapi\Session::createSchema example


<?php
$uri  = 'mysqlx://happyuser:password@127.0.0.1:33060/';
$sess = mysql_xdevapi\getSession($uri);

try {

    if ($schema = $sess->createSchema('fruit')) {
        echo "Info: I created a schema named 'fruit'\n";
    }
    
} catch (Exception $e) {

   echo $e->getMessage();

}
?>

   

The above example will output something similar to:


Info: I created a schema named 'fruit'


5.28.5 Session::dropSchema

Copyright 1997-2018 the PHP Documentation Group.

  • Session::dropSchema

    Drop a schema

Description

public bool mysql_xdevapi\Session::dropSchema(string schema_name);

Drop a schema (database).

Parameters

schema_name

Name of the schema to drop.

Return Values

TRUE if the schema is dropped, or FALSE if it does not exist or can't be dropped.

An E_WARNING level error is generated if the schema does not exist.

Examples

Example 5.112 mysql_xdevapi\Session::dropSchema example


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

$session->close();
?>


5.28.6 Session::executeSql

Copyright 1997-2018 the PHP Documentation Group.

  • Session::executeSql

    Execute an SQL statement

Description

public Object mysql_xdevapi\Session::executeSql(string statement);

Execute an SQL statement, similar to executing the sql() and execute() methods.

Parameters

statement

SQL statement to execute

Return Values

An SqlStatementResult object on success, or throws an Exception if the SQL statement fails.

Examples

Example 5.113 mysql_xdevapi\Session::executeSql example


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

$session->executeSql("CREATE DATABASE addressbook");


5.28.7 Session::generateUUID

Copyright 1997-2018 the PHP Documentation Group.

  • Session::generateUUID

    Get new UUID

Description

public string mysql_xdevapi\Session::generateUUID();

Generate a Universal Unique IDentifier (UUID) generated according to RFC 4122.

Parameters

This function has no parameters.

Return Values

The UUID; a string with a length of 32.

Examples

Example 5.114 mysql_xdevapi\Session::generateUuid example


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

$uuid = $session->generateUuid();

var_dump($uuid);

   

The above example will output something similar to:


string(32) "484B18AC7980F8D4FE84613CDA5EE84B"


5.28.8 Session::getClientId

Copyright 1997-2018 the PHP Documentation Group.

  • Session::getClientId

    Get client ID

Description

public integer mysql_xdevapi\Session::getClientId();

Get ID of the connected client.

Parameters

This function has no parameters.

Return Values

ID of the connected client.

Examples

Example 5.115 mysql_xdevapi\Session::getClientId example


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

$clientid = $session->getClientId();

var_dump($clientid);

   

The above example will output something similar to:


int(53)


5.28.9 Session::getSchema

Copyright 1997-2018 the PHP Documentation Group.

  • Session::getSchema

    Get a new schema object

Description

public mysql_xdevapi\Schema mysql_xdevapi\Session::getSchema(string schema_name);

A new Schema object for the provided schema name.

Parameters

This function has no parameters.

Return Values

A Schema object.

Examples

Example 5.116 mysql_xdevapi\Session::getSchema example


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

print_r($schema);

   

The above example will output something similar to:


mysql_xdevapi\Schema Object
(
    [name] => addressbook
)


5.28.10 Session::getSchemas

Copyright 1997-2018 the PHP Documentation Group.

  • Session::getSchemas

    Get the schemas

Description

public array mysql_xdevapi\Session::getSchemas();

Get schema objects for all schemas available to the session.

Parameters

This function has no parameters.

Return Values

An array containing objects that represent all of the schemas available to the session.

Examples

Example 5.117 mysql_xdevapi\Session::getSchemas example


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

print_r($schemas);

   

The above example will output something similar to:


Array
(
    [0] => mysql_xdevapi\Schema Object
        (
            [name] => addressbook
        )
    [1] => mysql_xdevapi\Schema Object
        (
            [name] => information_schema
        )
    ...


5.28.11 Session::getServerVersion

Copyright 1997-2018 the PHP Documentation Group.

  • Session::getServerVersion

    Get server version

Description

public integer mysql_xdevapi\Session::getServerVersion();

Retrieve the MySQL server version for the session.

Parameters

This function has no parameters.

Return Values

The MySQL server version for the session, as an integer such as "80012".

Examples

Example 5.118 mysql_xdevapi\Session::getServerVersion example


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

$version = $session->getServerVersion();

var_dump($version);

   

The above example will output something similar to:


int(80012)


5.28.12 Session::killClient

Copyright 1997-2018 the PHP Documentation Group.

  • Session::killClient

    Kill the client

Description

public object mysql_xdevapi\Session::killClient(integer client_id);

Kill the selected client and terminate the collection

Warning

This function is currently not documented; only its argument list is available.

Parameters

client_id

A connection's client ID.

Return Values

Examples

Example 5.119 mysql_xdevapi\Session::killClient example


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

$clientid = $session->getClientId();

// ...

$session->killClient($clientid);


5.28.13 Session::listClients

Copyright 1997-2018 the PHP Documentation Group.

  • Session::listClients

    Get client list

Description

public array mysql_xdevapi\Session::listClients();

Get a list of client connections to the session's MySQL server.

Parameters

This function has no parameters.

Return Values

An array containing the currently logged clients. The array elements are "client_id", "user", "host", and "sql_session".

Examples

Example 5.120 mysql_xdevapi\Session::listClients example


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

$ids = $session->listClients();

var_dump($ids);
?>

   

The above example will output something similar to:


array(1) {
  [0]=>
  array(4) {
    ["client_id"]=>
    int(61)
    ["user"]=>
    string(4) "root"
    ["host"]=>
    string(9) "localhost"
    ["sql_session"]=>
    int(72)
  }
}


5.28.14 Session::quoteName

Copyright 1997-2018 the PHP Documentation Group.

  • Session::quoteName

    Add quotes

Description

public string mysql_xdevapi\Session::quoteName(string name);

A quoting function to escape SQL names and identifiers. It escapes the identifier given in accordance to the settings of the current connection. This escape function should not be used to escape values.

Parameters

name

The string to quote.

Return Values

The quoted string.

Examples

Example 5.121 mysql_xdevapi\Session::quoteName example


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

$first = "MySQL's test";
var_dump($first);
var_dump($session->quoteName($first));

$second = 'Another `test` "like" `this`';
var_dump($second);
var_dump($session->quoteName($second));
?>

   

The above example will output something similar to:


string(12) "MySQL's test"
string(14) "`MySQL's test`"

string(28) "Another `test` "like" `this`"
string(34) "`Another ``test`` "like" ``this```"


5.28.15 Session::releaseSavepoint

Copyright 1997-2018 the PHP Documentation Group.

  • Session::releaseSavepoint

    Release set savepoint

Description

public void mysql_xdevapi\Session::releaseSavepoint(string name);

Release a previously set savepoint.

Parameters

name

Name of the savepoint to release.

Return Values

An SqlStatementResult object.

Examples

Example 5.122 mysql_xdevapi\Session::releaseSavepoint example


<?php
$session    = mysql_xdevapi\getSession("mysqlx://user:password@localhost");
$collection = $session->getSchema("addressbook")->getCollection("friends");

$session->startTransaction();
$collection->add( '{"test1":1, "test2":2}' )->execute();

$savepoint = $session->setSavepoint();

$collection->add( '{"test3":3, "test4":4}' )->execute();

$session->releaseSavepoint($savepoint);
$session->rollback();
?>


5.28.16 Session::rollback

Copyright 1997-2018 the PHP Documentation Group.

  • Session::rollback

    Rollback transaction

Description

public void mysql_xdevapi\Session::rollback();

Rollback the transaction.

Parameters

This function has no parameters.

Return Values

An SqlStatementResult object.

Examples

Example 5.123 mysql_xdevapi\Session::rollback example


<?php
$session    = mysql_xdevapi\getSession("mysqlx://user:password@localhost");
$collection = $session->getSchema("addressbook")->getCollection("names");

$session->startTransaction();
$collection->add( '{"test1":1, "test2":2}' )->execute();

$savepoint = $session->setSavepoint();

$collection->add( '{"test3":3, "test4":4}' )->execute();

$session->releaseSavepoint($savepoint);
$session->rollback();
?>


5.28.17 Session::rollbackTo

Copyright 1997-2018 the PHP Documentation Group.

  • Session::rollbackTo

    Rollback transaction to savepoint

Description

public void mysql_xdevapi\Session::rollbackTo(string name);

Rollback the transaction back to the savepoint.

Parameters

name

Name of the savepoint to rollback to; case-insensitive.

Return Values

An SqlStatementResult object.

Examples

Example 5.124 mysql_xdevapi\Session::rollbackTo example


<?php
$session    = mysql_xdevapi\getSession("mysqlx://user:password@localhost");
$collection = $session->getSchema("addressbook")->getCollection("names");

$session->startTransaction();
$collection->add( '{"test1":1, "test2":2}' )->execute();

$savepoint1 = $session->setSavepoint();

$collection->add( '{"test3":3, "test4":4}' )->execute();

$savepoint2 = $session->setSavepoint();

$session->rollbackTo($savepoint1);
?>


5.28.18 Session::setSavepoint

Copyright 1997-2018 the PHP Documentation Group.

  • Session::setSavepoint

    Create savepoint

Description

public string mysql_xdevapi\Session::setSavepoint(string name);

Create a new savepoint for the transaction.

Warning

This function is currently not documented; only its argument list is available.

Parameters

name

The name of the savepoint. The name is auto-generated if the optional name parameter is not defined as 'SAVEPOINT1', 'SAVEPOINT2', and so on.

Return Values

The name of the save point.

Examples

Example 5.125 mysql_xdevapi\Session::setSavepoint example


<?php
$session    = mysql_xdevapi\getSession("mysqlx://user:password@localhost");
$collection = $session->getSchema("addressbook")->getCollection("names");

$session->startTransaction();
$collection->add( '{"test1":1, "test2":2}' )->execute();

$savepoint = $session->setSavepoint();

$collection->add( '{"test3":3, "test4":4}' )->execute();

$session->releaseSavepoint($savepoint);
$session->rollback();
?>


5.28.19 Session::sql

Copyright 1997-2018 the PHP Documentation Group.

  • Session::sql

    Execute SQL query

Description

public mysql_xdevapi\SqlStatement mysql_xdevapi\Session::sql(string query);

Create a native SQL statement. Placeholders are supported using the native "?" syntax. Use the execute method to execute the SQL statement.

Parameters

query

SQL statement to execute.

Return Values

An SqlStatement object.

Examples

Example 5.126 mysql_xdevapi\Session::sql example


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

$session->sql("CREATE DATABASE addressbook")->execute();
?>


5.28.20 Session::startTransaction

Copyright 1997-2018 the PHP Documentation Group.

  • Session::startTransaction

    Start transaction

Description

public void mysql_xdevapi\Session::startTransaction();

Start a new transaction.

Parameters

This function has no parameters.

Return Values

An SqlStatementResult object.

Examples

Example 5.127 mysql_xdevapi\Session::startTransaction example


<?php
$session    = mysql_xdevapi\getSession("mysqlx://user:password@localhost");
$collection = $session->getSchema("addressbook")->getCollection("friends");

$session->startTransaction();
$collection->add( '{"test1":1, "test2":2}' )->execute();

$savepoint = $session->setSavepoint();

$collection->add( '{"test3":3, "test4":4}' )->execute();

$session->releaseSavepoint($savepoint);
$session->rollback();
?>


5.29 SqlStatement class

Copyright 1997-2018 the PHP Documentation Group.

 mysql_xdevapi\SqlStatement {
mysql_xdevapi\SqlStatement Constants  const integer mysql_xdevapi\SqlStatement::EXECUTE_ASYNC = =1;
  const integer mysql_xdevapi\SqlStatement::BUFFERED = =2;
Properties  public statement ;
Methods  public mysql_xdevapi\SqlStatement mysql_xdevapi\SqlStatement::bind(string param);
  public mysql_xdevapi\Result mysql_xdevapi\SqlStatement::execute();
  public mysql_xdevapi\Result mysql_xdevapi\SqlStatement::getNextResult();
  public mysql_xdevapi\Result mysql_xdevapi\SqlStatement::getResult();
  public bool mysql_xdevapi\SqlStatement::hasMoreResults();
}

statement

mysql_xdevapi\SqlStatement::EXECUTE_ASYNC

mysql_xdevapi\SqlStatement::BUFFERED

5.29.1 SqlStatement::bind

Copyright 1997-2018 the PHP Documentation Group.

  • SqlStatement::bind

    Bind statement parameters

Description

public mysql_xdevapi\SqlStatement mysql_xdevapi\SqlStatement::bind(string param);

Warning

This function is currently not documented; only its argument list is available.

Parameters

param

Return Values

Examples

Example 5.128 mysql_xdevapi\SqlStatement::bind example


<?php

/* ... */

?>


5.29.2 SqlStatement::__construct

Copyright 1997-2018 the PHP Documentation Group.

  • SqlStatement::__construct

    Description constructor

Description

private mysql_xdevapi\SqlStatement::__construct();

Warning

This function is currently not documented; only its argument list is available.

Parameters

This function has no parameters.

Examples

Example 5.129 mysql_xdevapi\SqlStatement::__construct example


<?php

/* ... */

?>


5.29.3 SqlStatement::execute

Copyright 1997-2018 the PHP Documentation Group.

  • SqlStatement::execute

    Execute the operation

Description

public mysql_xdevapi\Result mysql_xdevapi\SqlStatement::execute();

Warning

This function is currently not documented; only its argument list is available.

Parameters

This function has no parameters.

Return Values

Examples

Example 5.130 mysql_xdevapi\SqlStatement::execute example


<?php

/* ... */

?>


5.29.4 SqlStatement::getNextResult

Copyright 1997-2018 the PHP Documentation Group.

  • SqlStatement::getNextResult

    Get next result

Description

public mysql_xdevapi\Result mysql_xdevapi\SqlStatement::getNextResult();

Warning

This function is currently not documented; only its argument list is available.

Parameters

This function has no parameters.

Return Values

Examples

Example 5.131 mysql_xdevapi\SqlStatement::getNextResult example


<?php

/* ... */

?>


5.29.5 SqlStatement::getResult

Copyright 1997-2018 the PHP Documentation Group.

  • SqlStatement::getResult

    Get result

Description

public mysql_xdevapi\Result mysql_xdevapi\SqlStatement::getResult();

Warning

This function is currently not documented; only its argument list is available.

Parameters

This function has no parameters.

Return Values

Examples

Example 5.132 mysql_xdevapi\SqlStatement::getResult example


<?php

/* ... */

?>


5.29.6 SqlStatement::hasMoreResults

Copyright 1997-2018 the PHP Documentation Group.

  • SqlStatement::hasMoreResults

    Check for more results

Description

public bool mysql_xdevapi\SqlStatement::hasMoreResults();

Warning

This function is currently not documented; only its argument list is available.

Parameters

This function has no parameters.

Return Values

TRUE if the result set has more objects to fetch.

Examples

Example 5.133 mysql_xdevapi\SqlStatement::hasMoreResults example


<?php

/* ... */

?>


5.30 SqlStatementResult class

Copyright 1997-2018 the PHP Documentation Group.

 mysql_xdevapi\SqlStatementResult {
mysql_xdevapi\SqlStatementResult , mysql_xdevapi\BaseResult , Traversable Methods  public array mysql_xdevapi\SqlStatementResult::fetchAll();
  public object mysql_xdevapi\SqlStatementResult::fetchOne();
  public integer mysql_xdevapi\SqlStatementResult::getAffectedItemsCount();
  public integer mysql_xdevapi\SqlStatementResult::getColumnCount();
  public array mysql_xdevapi\SqlStatementResult::getColumnNames();
  public Array mysql_xdevapi\SqlStatementResult::getColumns();
  public array mysql_xdevapi\SqlStatementResult::getGeneratedIds();
  public String mysql_xdevapi\SqlStatementResult::getLastInsertId();
  public array mysql_xdevapi\SqlStatementResult::getWarnings();
  public integer mysql_xdevapi\SqlStatementResult::getWarningCounts();
  public bool mysql_xdevapi\SqlStatementResult::hasData();
  public mysql_xdevapi\Result mysql_xdevapi\SqlStatementResult::nextResult();
}

5.30.1 SqlStatementResult::__construct

Copyright 1997-2018 the PHP Documentation Group.

  • SqlStatementResult::__construct

    Description constructor

Description

private mysql_xdevapi\SqlStatementResult::__construct();

Warning

This function is currently not documented; only its argument list is available.

Parameters

This function has no parameters.

Examples

Example 5.134 mysql_xdevapi\SqlStatementResult::__construct example


<?php

/* ... */

?>


5.30.2 SqlStatementResult::fetchAll

Copyright 1997-2018 the PHP Documentation Group.

  • SqlStatementResult::fetchAll

    Get all rows

Description

public array mysql_xdevapi\SqlStatementResult::fetchAll();

Warning

This function is currently not documented; only its argument list is available.

Parameters

This function has no parameters.

Return Values

Examples

Example 5.135 mysql_xdevapi\SqlStatementResult::fetchAll example


<?php

/* ... */

?>


5.30.3 SqlStatementResult::fetchOne

Copyright 1997-2018 the PHP Documentation Group.

  • SqlStatementResult::fetchOne

    Get single row

Description

public object mysql_xdevapi\SqlStatementResult::fetchOne();

Warning

This function is currently not documented; only its argument list is available.

Parameters

This function has no parameters.

Return Values

Examples

Example 5.136 mysql_xdevapi\SqlStatementResult::fetchOne example


<?php

/* ... */

?>


5.30.4 SqlStatementResult::getAffectedItemsCount

Copyright 1997-2018 the PHP Documentation Group.

  • SqlStatementResult::getAffectedItemsCount

    Get affected row count

Description

public integer mysql_xdevapi\SqlStatementResult::getAffectedItemsCount();

Warning

This function is currently not documented; only its argument list is available.

Parameters

This function has no parameters.

Return Values

Examples

Example 5.137 mysql_xdevapi\SqlStatementResult::getAffectedItemsCount example


<?php

/* ... */

?>


5.30.5 SqlStatementResult::getColumnCount

Copyright 1997-2018 the PHP Documentation Group.

  • SqlStatementResult::getColumnCount

    Get column count

Description

public integer mysql_xdevapi\SqlStatementResult::getColumnCount();

Warning

This function is currently not documented; only its argument list is available.

Parameters

This function has no parameters.

Return Values

Examples

Example 5.138 mysql_xdevapi\SqlStatementResult::getColumnCount example


<?php

/* ... */

?>


5.30.6 SqlStatementResult::getColumnNames

Copyright 1997-2018 the PHP Documentation Group.

  • SqlStatementResult::getColumnNames

    Get column names

Description

public array mysql_xdevapi\SqlStatementResult::getColumnNames();

Warning

This function is currently not documented; only its argument list is available.

Parameters

This function has no parameters.

Return Values

Examples

Example 5.139 mysql_xdevapi\SqlStatementResult::getColumnNames example


<?php

/* ... */

?>


5.30.7 SqlStatementResult::getColumns

Copyright 1997-2018 the PHP Documentation Group.

  • SqlStatementResult::getColumns

    Get columns

Description

public Array mysql_xdevapi\SqlStatementResult::getColumns();

Warning

This function is currently not documented; only its argument list is available.

Parameters

This function has no parameters.

Return Values

Examples

Example 5.140 mysql_xdevapi\SqlStatementResult::getColumns example


<?php

/* ... */

?>


5.30.8 SqlStatementResult::getGeneratedIds

Copyright 1997-2018 the PHP Documentation Group.

  • SqlStatementResult::getGeneratedIds

    Get generated ids

Description

public array mysql_xdevapi\SqlStatementResult::getGeneratedIds();

Warning

This function is currently not documented; only its argument list is available.

Parameters

This function has no parameters.

Return Values

An array of generated IDs from the last operation.

Examples

Example 5.141 mysql_xdevapi\SqlStatementResult::getGeneratedIds example


<?php

/* ... */

?>


5.30.9 SqlStatementResult::getLastInsertId

Copyright 1997-2018 the PHP Documentation Group.

  • SqlStatementResult::getLastInsertId

    Get last insert id

Description

public String mysql_xdevapi\SqlStatementResult::getLastInsertId();

Warning

This function is currently not documented; only its argument list is available.

Parameters

This function has no parameters.

Return Values

The ID for the last insert operation.

Examples

Example 5.142 mysql_xdevapi\SqlStatementResult::getLastInsertId example


<?php

/* ... */

?>


5.30.10 SqlStatementResult::getWarnings

Copyright 1997-2018 the PHP Documentation Group.

  • SqlStatementResult::getWarnings

    Get warnings from last operation

Description

public array mysql_xdevapi\SqlStatementResult::getWarnings();

Warning

This function is currently not documented; only its argument list is available.

Parameters

This function has no parameters.

Return Values

All warnings raised by the last CRUD operation, as an array.

Examples

Example 5.143 mysql_xdevapi\SqlStatementResult::getWarnings example


<?php

/* ... */

?>


5.30.11 SqlStatementResult::getWarningsCount

Copyright 1997-2018 the PHP Documentation Group.

  • SqlStatementResult::getWarningsCount

    Get warning count from last operation

Description

public integer mysql_xdevapi\SqlStatementResult::getWarningCounts();

Warning

This function is currently not documented; only its argument list is available.

Parameters

This function has no parameters.

Return Values

The number of warnings raised during the last CRUD operation.

Examples

Example 5.144 mysql_xdevapi\SqlStatementResult::getWarningsCount example


<?php

/* ... */

?>


5.30.12 SqlStatementResult::hasData

Copyright 1997-2018 the PHP Documentation Group.

  • SqlStatementResult::hasData

    Check if result has data

Description

public bool mysql_xdevapi\SqlStatementResult::hasData();

Warning

This function is currently not documented; only its argument list is available.

Parameters

This function has no parameters.

Return Values

TRUE if the result set has data.

Examples

Example 5.145 mysql_xdevapi\SqlStatementResult::hasData example


<?php

/* ... */

?>


5.30.13 SqlStatementResult::nextResult

Copyright 1997-2018 the PHP Documentation Group.

  • SqlStatementResult::nextResult

    Get next result

Description

public mysql_xdevapi\Result mysql_xdevapi\SqlStatementResult::nextResult();

Warning

This function is currently not documented; only its argument list is available.

Parameters

This function has no parameters.

Return Values

The next Result object from the result set.

Examples

Example 5.146 mysql_xdevapi\SqlStatementResult::nextResult example


<?php

/* ... */

?>


5.31 Statement class

Copyright 1997-2018 the PHP Documentation Group.

 mysql_xdevapi\Statement {
mysql_xdevapi\Statement Constants  const integer mysql_xdevapi\Statement::EXECUTE_ASYNC = =1;
  const integer mysql_xdevapi\Statement::BUFFERED = =2;
Methods  public mysql_xdevapi\Result mysql_xdevapi\Statement::getNextResult();
  public mysql_xdevapi\Result mysql_xdevapi\Statement::getResult();
  public bool mysql_xdevapi\Statement::hasMoreResults();
}

mysql_xdevapi\Statement::EXECUTE_ASYNC

mysql_xdevapi\Statement::BUFFERED

5.31.1 Statement::__construct

Copyright 1997-2018 the PHP Documentation Group.

  • Statement::__construct

    Description constructor

Description

private mysql_xdevapi\Statement::__construct();

Warning

This function is currently not documented; only its argument list is available.

Parameters

This function has no parameters.

Examples

Example 5.147 mysql_xdevapi\Statement::__construct example


<?php

/* ... */

?>


5.31.2 Statement::getNextResult

Copyright 1997-2018 the PHP Documentation Group.

  • Statement::getNextResult

    Get next result

Description

public mysql_xdevapi\Result mysql_xdevapi\Statement::getNextResult();

Warning

This function is currently not documented; only its argument list is available.

Parameters

This function has no parameters.

Return Values

Examples

Example 5.148 mysql_xdevapi\Statement::getNextResult example


<?php

/* ... */

?>


5.31.3 Statement::getResult

Copyright 1997-2018 the PHP Documentation Group.

  • Statement::getResult

    Get result

Description

public mysql_xdevapi\Result mysql_xdevapi\Statement::getResult();

Warning

This function is currently not documented; only its argument list is available.

Parameters

This function has no parameters.

Return Values

Examples

Example 5.149 mysql_xdevapi\Statement::getResult example


<?php

/* ... */

?>


5.31.4 Statement::hasMoreResults

Copyright 1997-2018 the PHP Documentation Group.

  • Statement::hasMoreResults

    Check if more results

Description

public bool mysql_xdevapi\Statement::hasMoreResults();

Warning

This function is currently not documented; only its argument list is available.

Parameters

This function has no parameters.

Return Values

Examples

Example 5.150 mysql_xdevapi\Statement::hasMoreResults example


<?php

/* ... */

?>


5.32 Table class

Copyright 1997-2018 the PHP Documentation Group.

Provides access to the table through INSERT/SELECT/UPDATE/DELETE statements.

 mysql_xdevapi\Table {
mysql_xdevapi\Table , mysql_xdevapi\SchemaObject Properties  public name ;
Methods  public integer mysql_xdevapi\Table::count();
  public mysql_xdevapi\TableDelete mysql_xdevapi\Table::delete();
  public bool mysql_xdevapi\Table::existsInDatabase();
  public string mysql_xdevapi\Table::getName();
  public mysql_xdevapi\Schema mysql_xdevapi\Table::getSchema();
  public mysql_xdevapi\Session mysql_xdevapi\Table::getSession();
  public mysql_xdevapi\TableInsert mysql_xdevapi\Table::insert(mixed columns,
                                                               mixed ...);

  public bool mysql_xdevapi\Table::isView();
  public mysql_xdevapi\TableSelect mysql_xdevapi\Table::select(mixed columns,
                                                               mixed ...);

  public mysql_xdevapi\TableUpdate mysql_xdevapi\Table::update();
}

name

5.32.1 Table::__construct

Copyright 1997-2018 the PHP Documentation Group.

  • Table::__construct

    Table constructor

Description

private mysql_xdevapi\Table::__construct();

Construct a table object.

Parameters

This function has no parameters.

Examples

Example 5.151 mysql_xdevapi\Table::__construct example


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

$schema = $session->getSchema("addressbook");
$table  = $schema->getTable("names");
?>


5.32.2 Table::count

Copyright 1997-2018 the PHP Documentation Group.

  • Table::count

    Get row count

Description

public integer mysql_xdevapi\Table::count();

Fetch the number of rows in the table.

Parameters

This function has no parameters.

Return Values

The total number of rows in the table.

Examples

Example 5.152 mysql_xdevapi\Table::count example


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

$session->sql("DROP DATABASE IF EXISTS addressbook")->execute();
$session->sql("CREATE DATABASE addressbook")->execute();
$session->sql("CREATE TABLE addressbook.names(name text, age int)")->execute();
$session->sql("INSERT INTO addressbook.names values ('John', 42), ('Sam', 33)")->execute();

$schema = $session->getSchema("addressbook");
$table  = $schema->getTable("names");

var_dump($table->count());
?>

   

The above example will output:


int(2)


5.32.3 Table::delete

Copyright 1997-2018 the PHP Documentation Group.

  • Table::delete

    Delete rows from table

Description

public mysql_xdevapi\TableDelete mysql_xdevapi\Table::delete();

Deletes rows from a table.

Parameters

This function has no parameters.

Return Values

A TableDelete object; use the execute() method to execute the delete query.

Examples

Example 5.153 mysql_xdevapi\Table::delete example


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

$session->sql("DROP DATABASE IF EXISTS addressbook")->execute();
$session->sql("CREATE DATABASE addressbook")->execute();
$session->sql("CREATE TABLE addressbook.names(name text, age int)")->execute();
$session->sql("INSERT INTO addressbook.names values ('John', 42), ('Sam', 33)")->execute();

$schema = $session->getSchema("addressbook");
$table  = $schema->getTable("names");

$table->delete()->where("name = :name")->orderby("age DESC")->limit(1)->bind(['name' => 'John'])->execute();
?>


5.32.4 Table::existsInDatabase

Copyright 1997-2018 the PHP Documentation Group.

  • Table::existsInDatabase

    Check if table exists in database

Description

public bool mysql_xdevapi\Table::existsInDatabase();

Verifies if this table exists in the database.

Parameters

This function has no parameters.

Return Values

Returns TRUE if table exists in the database, else FALSE if it does not.

Examples

Example 5.154 mysql_xdevapi\Table::existsInDatabase example


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

$session->sql("DROP DATABASE IF EXISTS addressbook")->execute();
$session->sql("CREATE DATABASE addressbook")->execute();
$session->sql("CREATE TABLE addressbook.names(name text, age int)")->execute();
$session->sql("INSERT INTO addressbook.names values ('John', 42), ('Sam', 33)")->execute();

$schema = $session->getSchema("addressbook");
$table  = $schema->getTable("names");

if ($table->existsInDatabase()) {
  echo "Yes, this table still exists in the session's schema.";
}
?>

   

The above example will output something similar to:


Yes, this table still exists in the session's schema.


5.32.5 Table::getName

Copyright 1997-2018 the PHP Documentation Group.

  • Table::getName

    Get table name

Description

public string mysql_xdevapi\Table::getName();

Returns the name of this database object.

Parameters

This function has no parameters.

Return Values

The name of this database object.

Examples

Example 5.155 mysql_xdevapi\Table::getName example


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

$session->sql("DROP DATABASE IF EXISTS addressbook")->execute();
$session->sql("CREATE DATABASE addressbook")->execute();
$session->sql("CREATE TABLE addressbook.names(name text, age int)")->execute();
$session->sql("INSERT INTO addressbook.names values ('John', 42), ('Sam', 33)")->execute();

$schema = $session->getSchema("addressbook");
$table  = $schema->getTable("names");

var_dump($table->getName());
?>

   

The above example will output something similar to:


string(5) "names"


5.32.6 Table::getSchema

Copyright 1997-2018 the PHP Documentation Group.

  • Table::getSchema

    Get table schema

Description

public mysql_xdevapi\Schema mysql_xdevapi\Table::getSchema();

Fetch the schema associated with the table.

Parameters

This function has no parameters.

Return Values

A Schema object.

Examples

Example 5.156 mysql_xdevapi\Table::getSchema example


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

$session->sql("DROP DATABASE IF EXISTS addressbook")->execute();
$session->sql("CREATE DATABASE addressbook")->execute();
$session->sql("CREATE TABLE addressbook.names(name text, age int)")->execute();
$session->sql("INSERT INTO addressbook.names values ('John', 42), ('Sam', 33)")->execute();

$schema = $session->getSchema("addressbook");
$table  = $schema->getTable("names");

var_dump($table->getSchema());
?>

   

The above example will output something similar to:


object(mysql_xdevapi\Schema)#9 (1) {
  ["name"]=>
  string(11) "addressbook"
}


5.32.7 Table::getSession

Copyright 1997-2018 the PHP Documentation Group.

  • Table::getSession

    Get table session

Description

public mysql_xdevapi\Session mysql_xdevapi\Table::getSession();

Get session associated with the table.

Parameters

This function has no parameters.

Return Values

A Session object.

Examples

Example 5.157 mysql_xdevapi\Table::getSession example


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

$session->sql("DROP DATABASE IF EXISTS addressbook")->execute();
$session->sql("CREATE DATABASE addressbook")->execute();
$session->sql("CREATE TABLE addressbook.names(name text, age int)")->execute();
$session->sql("INSERT INTO addressbook.names values ('John', 42), ('Sam', 33)")->execute();

$schema = $session->getSchema("addressbook");
$table  = $schema->getTable("names");

var_dump($table->getSession());
?>

   

The above example will output something similar to:


object(mysql_xdevapi\Session)#9 (0) {
}


5.32.8 Table::insert

Copyright 1997-2018 the PHP Documentation Group.

  • Table::insert

    Insert table rows

Description

public mysql_xdevapi\TableInsert mysql_xdevapi\Table::insert(mixed columns,
                                                             mixed ...);

Inserts rows into a table.

Parameters

columns

The columns to insert data into. Can be an array with one or more values, or a string.

...

Additional columns definitions.

Return Values

A TableInsert object; use the execute() method to execute the insert statement.

Examples

Example 5.158 mysql_xdevapi\Table::insert example


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

$session->sql("DROP DATABASE IF EXISTS addressbook")->execute();
$session->sql("CREATE DATABASE addressbook")->execute();
$session->sql("CREATE TABLE addressbook.names(name text, age int)")->execute();
$session->sql("INSERT INTO addressbook.names values ('John', 42), ('Sam', 33)")->execute();

$schema = $session->getSchema("addressbook");
$table  = $schema->getTable("names");

$table->insert("name", "age")->values(["Suzanne", 31],["Julie", 43]);
?>


5.32.9 Table::isView

Copyright 1997-2018 the PHP Documentation Group.

  • Table::isView

    Check if table is view

Description

public bool mysql_xdevapi\Table::isView();

Determine if the underlying object is a view or not.

Parameters

This function has no parameters.

Return Values

TRUE if the underlying object is a view, otherwise FALSE.

Examples

Example 5.159 mysql_xdevapi\Table::isView example


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

$session->sql("DROP DATABASE IF EXISTS addressbook")->execute();
$session->sql("CREATE DATABASE addressbook")->execute();
$session->sql("CREATE TABLE addressbook.names(name text, age int)")->execute();
$session->sql("INSERT INTO addressbook.names values ('John', 42), ('Sam', 33)")->execute();

$schema = $session->getSchema("addressbook");
$table  = $schema->getTable("names

if ($table->isView()) {
    echo "This is a view.";
} else {
    echo "This is not a view.";
}
?>

   

The above example will output:


int(2)


5.32.10 Table::select

Copyright 1997-2018 the PHP Documentation Group.

  • Table::select

    Select rows from table

Description

public mysql_xdevapi\TableSelect mysql_xdevapi\Table::select(mixed columns,
                                                             mixed ...);

Fetches data from a table.

Parameters

columns

The columns to select data from. Can be an array with one or more values, or a string.

...

Additional columns parameter definitions.

Return Values

A TableSelect object; use the execute() method to execute the select and return a RowResult object.

Examples

Example 5.160 mysql_xdevapi\Table::count example


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

$session->sql("DROP DATABASE IF EXISTS addressbook")->execute();
$session->sql("CREATE DATABASE addressbook")->execute();
$session->sql("CREATE TABLE addressbook.names(name text, age int)")->execute();
$session->sql("INSERT INTO addressbook.names values ('John', 42), ('Sam', 33)")->execute();

$schema = $session->getSchema("addressbook");
$table  = $schema->getTable("names");

$row = $table->select('name', 'age')->execute()->fetchAll();

print_r($row);

   

The above example will output something similar to:


Array
(
    [0] => Array
        (
            [name] => John
            [age] => 42
        )
    [1] => Array
        (
            [name] => Sam
            [age] => 33
        )
)


5.32.11 Table::update

Copyright 1997-2018 the PHP Documentation Group.

  • Table::update

    Update rows in table

Description

public mysql_xdevapi\TableUpdate mysql_xdevapi\Table::update();

Updates columns in a table.

Parameters

This function has no parameters.

Return Values

A TableUpdate object; use the execute() method to execute the update statement.

Examples

Example 5.161 mysql_xdevapi\Table::update example


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

$session->sql("DROP DATABASE IF EXISTS addressbook")->execute();
$session->sql("CREATE DATABASE addressbook")->execute();
$session->sql("CREATE TABLE addressbook.names(name text, age int)")->execute();
$session->sql("INSERT INTO addressbook.names values ('John', 42), ('Sam', 33)")->execute();

$schema = $session->getSchema("addressbook");
$table  = $schema->getTable("names");

$table->update()->set('age',34)->where('name = "Sam"')->limit(1)->execute();
?>


5.33 TableDelete class

Copyright 1997-2018 the PHP Documentation Group.

A statement for delete operations on Table.

 mysql_xdevapi\TableDelete {
mysql_xdevapi\TableDelete , mysql_xdevapi\Executable Methods  public mysql_xdevapi\TableDelete mysql_xdevapi\TableDelete::bind(array placeholder_values);
  public mysql_xdevapi\Result mysql_xdevapi\TableDelete::execute();
  public mysql_xdevapi\TableDelete mysql_xdevapi\TableDelete::limit(integer rows);
  public mysql_xdevapi\TableDelete mysql_xdevapi\TableDelete::offset(integer position);
  public mysql_xdevapi\TableDelete mysql_xdevapi\TableDelete::orderby(string orderby_expr);
  public mysql_xdevapi\TableDelete mysql_xdevapi\TableDelete::where(string where_expr);
}

5.33.1 TableDelete::bind

Copyright 1997-2018 the PHP Documentation Group.

  • TableDelete::bind

    Bind delete query parameters

Description

public mysql_xdevapi\TableDelete mysql_xdevapi\TableDelete::bind(array placeholder_values);

Binds a value to a specific placeholder.

Parameters

placeholder_values

The name of the placeholder and the value to bind.

Return Values

A TableDelete object.

Examples

Example 5.162 mysql_xdevapi\TableDelete::bind example


<?php

$table->delete()->where("name = :name")->orderby("id DESC")->limit(2)->bind(['name' => 'Cassidy'])->execute();

?>


5.33.2 TableDelete::__construct

Copyright 1997-2018 the PHP Documentation Group.

  • TableDelete::__construct

    TableDelete constructor

Description

private mysql_xdevapi\TableDelete::__construct();

Parameters

This function has no parameters.

Examples

Example 5.163 mysql_xdevapi\TableDelete::__construct example


<?php

/* ... */

?>


5.33.3 TableDelete::execute

Copyright 1997-2018 the PHP Documentation Group.

  • TableDelete::execute

    Execute delete query

Description

public mysql_xdevapi\Result mysql_xdevapi\TableDelete::execute();

Execute the delete query.

Parameters

This function has no parameters.

Return Values

A Result object.

Examples

Example 5.164 mysql_xdevapi\TableDelete::execute example


<?php

$res = $table->delete()->where('name = \'user_name\'')->limit(1)->execute();

?>


5.33.4 TableDelete::limit

Copyright 1997-2018 the PHP Documentation Group.

  • TableDelete::limit

    Limit deleted rows

Description

public mysql_xdevapi\TableDelete mysql_xdevapi\TableDelete::limit(integer rows);

Sets the maximum number of records or documents to delete.

Parameters

rows

The maximum number of records or documents to delete.

Return Values

TableDelete object.

Examples

Example 5.165 mysql_xdevapi\TableDelete::limit example


<?php

$table->delete()->where("name = :name")->orderby("id DESC")->limit(2)->bind(['name' => 'Cassidy'])->execute();

?>


5.33.5 TableDelete::offset

Copyright 1997-2018 the PHP Documentation Group.

  • TableDelete::offset

    Set delete limit offset

Description

public mysql_xdevapi\TableDelete mysql_xdevapi\TableDelete::offset(integer position);

Sets the limit offset.

Parameters

position

The limit offset.

Return Values

A TableDelete object.

Examples

Example 5.166 mysql_xdevapi\TableDelete::offset example


<?php

$table->delete()->where('age = 17')->orderby('name desc')->limit(3)->offset(0)->execute();

?>


5.33.6 TableDelete::orderby

Copyright 1997-2018 the PHP Documentation Group.

  • TableDelete::orderby

    Set delete sort criteria

Description

public mysql_xdevapi\TableDelete mysql_xdevapi\TableDelete::orderby(string orderby_expr);

Set the order options for a result set.

Parameters

orderby_expr

The sort definition.

Return Values

A TableDelete object.

Examples

Example 5.167 mysql_xdevapi\TableDelete::orderby example


<?php

$res = $table->select('a as aa','b as bb','c as cc')->orderby('b desc','a desc')->execute();

?>


5.33.7 TableDelete::where

Copyright 1997-2018 the PHP Documentation Group.

  • TableDelete::where

    Set delete search condition

Description

public mysql_xdevapi\TableDelete mysql_xdevapi\TableDelete::where(string where_expr);

Sets the search condition to filter.

Parameters

where_expr

Define the search condition to filter documents or records.

Return Values

TableDelete object.

Examples

Example 5.168 mysql_xdevapi\TableDelete::where example


<?php

$table->delete()->orderby('age desc')->where('age < 20 and age > 12 and name != :name')->bind(['name' => 'Tierney'])->limit(2)->execute();

?>


5.34 TableInsert class

Copyright 1997-2018 the PHP Documentation Group.

A statement for insert operations on Table.

 mysql_xdevapi\TableInsert {
mysql_xdevapi\TableInsert , mysql_xdevapi\Executable Methods  public mysql_xdevapi\Result mysql_xdevapi\TableInsert::execute();
  public mysql_xdevapi\TableInsert mysql_xdevapi\TableInsert::values(array row_values);
}

5.34.1 TableInsert::__construct

Copyright 1997-2018 the PHP Documentation Group.

  • TableInsert::__construct

    TableInsert constructor

Description

private mysql_xdevapi\TableInsert::__construct();

Parameters

This function has no parameters.

Examples

Example 5.169 mysql_xdevapi\TableInsert::__construct example


<?php

/* ... */

?>


5.34.2 TableInsert::execute

Copyright 1997-2018 the PHP Documentation Group.

  • TableInsert::execute

    Execute insert query

Description

public mysql_xdevapi\Result mysql_xdevapi\TableInsert::execute();

Execute the statement.

Parameters

This function has no parameters.

Return Values

A Result object.

Examples

Example 5.170 mysql_xdevapi\TableInsert::execute example


<?php

$res = $table->insert(['x'])->values([1])->values([2])->values([3])->execute();

?>


5.34.3 TableInsert::values

Copyright 1997-2018 the PHP Documentation Group.

  • TableInsert::values

    Add insert row values

Description

public mysql_xdevapi\TableInsert mysql_xdevapi\TableInsert::values(array row_values);

Set the values to be inserted.

Parameters

row_values

Values (an array) of columns to insert.

Return Values

A TableInsert object.

Examples

Example 5.171 mysql_xdevapi\TableInsert::values example


<?php

$res = $table->insert("name", "age")->values(["Oracila", 1800])->execute();

?>


5.35 TableSelect class

Copyright 1997-2018 the PHP Documentation Group.

A statement for record retrieval operations on a Table.

 mysql_xdevapi\TableSelect {
mysql_xdevapi\TableSelect , mysql_xdevapi\Executable Methods  public mysql_xdevapi\TableSelect mysql_xdevapi\TableSelect::bind(array placeholder_values);
  public mysql_xdevapi\RowResult mysql_xdevapi\TableSelect::execute();
  public mysql_xdevapi\TableSelect mysql_xdevapi\TableSelect::groupBy(mixed sort_expr);
  public mysql_xdevapi\TableSelect mysql_xdevapi\TableSelect::having(string sort_expr);
  public mysql_xdevapi\TableSelect mysql_xdevapi\TableSelect::limit(integer rows);
  public mysql_xdevapi\TableSelect mysql_xdevapi\TableSelect::lockExclusive(integer lock_waiting_option);
  public mysql_xdevapi\TableSelect mysql_xdevapi\TableSelect::lockShared(integer lock_waiting_option);
  public mysql_xdevapi\TableSelect mysql_xdevapi\TableSelect::offset(integer position);
  public mysql_xdevapi\TableSelect mysql_xdevapi\TableSelect::orderby(mixed sort_expr,
                                                                      mixed ...);

  public mysql_xdevapi\TableSelect mysql_xdevapi\TableSelect::where(string where_expr);
}

5.35.1 TableSelect::bind

Copyright 1997-2018 the PHP Documentation Group.

  • TableSelect::bind

    Bind select query parameters

Description

public mysql_xdevapi\TableSelect mysql_xdevapi\TableSelect::bind(array placeholder_values);

Binds a value to a specific placeholder.

Parameters

placeholder_values

The name of the placeholder, and the value to bind.

Return Values

A TableSelect object.

Examples

Example 5.172 mysql_xdevapi\TableSelect::bind example


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

$schema = $session->getSchema("addressbook");
$table  = $schema->getTable("names");

$result = $table->select('name','age')
  ->where('name like :name and age > :age')
  ->bind(['name' => 'John', 'age' => 42])
  ->execute();

$row = $result->fetchAll();
print_r($row);
?>

   

The above example will output something similar to:


Array
(
    [0] => Array
        (
            [name] => John
            [age] => 42
        )
)


5.35.2 TableSelect::__construct

Copyright 1997-2018 the PHP Documentation Group.

  • TableSelect::__construct

    TableSelect constructor

Description

private mysql_xdevapi\TableSelect::__construct();

An object returned by the select() method; use execute() to execute the query.

Parameters

This function has no parameters.

Examples

Example 5.173 mysql_xdevapi\TableSelect::__construct example


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

$session->sql("DROP DATABASE IF EXISTS addressbook")->execute();
$session->sql("CREATE DATABASE addressbook")->execute();
$session->sql("CREATE TABLE addressbook.names(name text, age int)")->execute();
$session->sql("INSERT INTO addressbook.names values ('John', 42), ('Sam', 33)")->execute();

$schema = $session->getSchema("addressbook");
$table  = $schema->getTable("names");

$result = $table->select('name','age')
  ->where('name like :name and age > :age')
  ->bind(['name' => 'John', 'age' => 42])
  ->orderBy('age desc')
  ->execute();

$row = $result->fetchAll();
print_r($row);

?>

   

The above example will output something similar to:


Array
(
    [0] => Array
        (
            [name] => John
            [age] => 42
        )
)


5.35.3 TableSelect::execute

Copyright 1997-2018 the PHP Documentation Group.

  • TableSelect::execute

    Execute select statement

Description

public mysql_xdevapi\RowResult mysql_xdevapi\TableSelect::execute();

Execute the select statement by chaining it with the execute() method.

Parameters

This function has no parameters.

Return Values

A RowResult object.

Examples

Example 5.174 mysql_xdevapi\TableSelect::execute example


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

$schema = $session->getSchema("addressbook");
$table  = $schema->getTable("names");

$result = $table->select('name','age')
  ->where('name like :name and age > :age')
  ->bind(['name' => 'John', 'age' => 42])
  ->orderBy('age desc')
  ->execute();

$row = $result->fetchAll();
?>

   

The above example will output something similar to:


Array
(
    [0] => Array
        (
            [name] => John
            [age] => 42
        )
)


5.35.4 TableSelect::groupBy

Copyright 1997-2018 the PHP Documentation Group.

  • TableSelect::groupBy

    Set select grouping criteria

Description

public mysql_xdevapi\TableSelect mysql_xdevapi\TableSelect::groupBy(mixed sort_expr);

Sets a grouping criteria for the result set.

Parameters

sort_expr

The grouping criteria.

Return Values

A TableSelect object.

Examples

Example 5.175 mysql_xdevapi\TableSelect::groupBy example


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

$session->sql("DROP DATABASE IF EXISTS addressbook")->execute();
$session->sql("CREATE DATABASE addressbook")->execute();
$session->sql("CREATE TABLE addressbook.names(name text, age int)")->execute();
$session->sql("INSERT INTO addressbook.names values ('John', 42), ('Sam', 42)")->execute();
$session->sql("INSERT INTO addressbook.names values ('Suki', 31)")->execute();

$schema = $session->getSchema("addressbook");
$table  = $schema->getTable("names");

$result = $table->select('count(*) as count', 'age')
  ->groupBy('age')->orderBy('age asc')
  ->execute();

$row = $result->fetchAll();
print_r($row);
?>

   

The above example will output something similar to:


Array
(
    [0] => Array
        (
            [count] => 1
            [age] => 31
        )
    [1] => Array
        (
            [count] => 2
            [age] => 42
        )
)


5.35.5 TableSelect::having

Copyright 1997-2018 the PHP Documentation Group.

  • TableSelect::having

    Set select having condition

Description

public mysql_xdevapi\TableSelect mysql_xdevapi\TableSelect::having(string sort_expr);

Sets a condition for records to consider in aggregate function operations.

Parameters

sort_expr

A condition on the aggregate functions used on the grouping criteria.

Return Values

A TableSelect object.

Examples

Example 5.176 mysql_xdevapi\TableSelect::having example


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

$session->sql("DROP DATABASE IF EXISTS addressbook")->execute();
$session->sql("CREATE DATABASE addressbook")->execute();
$session->sql("CREATE TABLE addressbook.names(name text, age int)")->execute();
$session->sql("INSERT INTO addressbook.names values ('John', 42), ('Sam', 42)")->execute();
$session->sql("INSERT INTO addressbook.names values ('Suki', 31)")->execute();

$schema = $session->getSchema("addressbook");
$table  = $schema->getTable("names");

$result = $table->select('count(*) as count', 'age')
  ->groupBy('age')->orderBy('age asc')
  ->having('count > 1')
  ->execute();

$row = $result->fetchAll();
print_r($row);
?>

   

The above example will output something similar to:


Array
(
    [0] => Array
        (
            [count] => 2
            [age] => 42
        )
)


5.35.6 TableSelect::limit

Copyright 1997-2018 the PHP Documentation Group.

  • TableSelect::limit

    Limit selected rows

Description

public mysql_xdevapi\TableSelect mysql_xdevapi\TableSelect::limit(integer rows);

Sets the maximum number of records or documents to return.

Parameters

rows

The maximum number of records or documents.

Return Values

A TableSelect object.

Examples

Example 5.177 mysql_xdevapi\TableSelect::limit example


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

$schema = $session->getSchema("addressbook");
$table  = $schema->getTable("names");

$result = $table->select('name', 'age')
  ->limit(1)
  ->execute();

$row = $result->fetchAll();
print_r($row);
?>

   

The above example will output something similar to:


Array
(
    [0] => Array
        (
            [name] => John
            [age] => 42
        )
)


5.35.7 TableSelect::lockExclusive

Copyright 1997-2018 the PHP Documentation Group.

  • TableSelect::lockExclusive

    Execute EXCLUSIVE LOCK

Description

public mysql_xdevapi\TableSelect mysql_xdevapi\TableSelect::lockExclusive(integer lock_waiting_option);

Execute a read operation with EXCLUSIVE LOCK. Only one lock can be active at a time.

Parameters

lock_waiting_option

The optional waiting option that defaults to MYSQLX_LOCK_DEFAULT. Valid values are:

  • MYSQLX_LOCK_DEFAULT

  • MYSQLX_LOCK_NOWAIT

  • MYSQLX_LOCK_SKIP_LOCKED

Return Values

TableSelect object.

Examples

Example 5.178 mysql_xdevapi\TableSelect::lockExclusive example


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

$schema = $session->getSchema("addressbook");
$table  = $schema->getTable("names");

$session->startTransaction();

$result = $table->select('name', 'age')
  ->lockExclusive(MYSQLX_LOCK_NOWAIT)
  ->execute();

$session->commit();

$row = $result->fetchAll();
print_r($row);
?>

   

The above example will output something similar to:


Array
(
    [0] => Array
        (
            [name] => John
            [age] => 42
        )
    [1] => Array
        (
            [name] => Sam
            [age] => 42
        )
)


5.35.8 TableSelect::lockShared

Copyright 1997-2018 the PHP Documentation Group.

  • TableSelect::lockShared

    Execute SHARED LOCK

Description

public mysql_xdevapi\TableSelect mysql_xdevapi\TableSelect::lockShared(integer lock_waiting_option);

Execute a read operation with SHARED LOCK. Only one lock can be active at a time.

Parameters

lock_waiting_option

The optional waiting option that defaults to MYSQLX_LOCK_DEFAULT. Valid values are:

  • MYSQLX_LOCK_DEFAULT

  • MYSQLX_LOCK_NOWAIT

  • MYSQLX_LOCK_SKIP_LOCKED

Return Values

A TableSelect object.

Examples

Example 5.179 mysql_xdevapi\TableSelect::lockShared example


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

$schema = $session->getSchema("addressbook");
$table  = $schema->getTable("names");

$session->startTransaction();

$result = $table->select('name', 'age')
  ->lockShared(MYSQLX_LOCK_NOWAIT)
  ->execute();

$session->commit();

$row = $result->fetchAll();
print_r($row);
?>

   

The above example will output something similar to:


Array
(
    [0] => Array
        (
            [name] => John
            [age] => 42
        )
    [1] => Array
        (
            [name] => Sam
            [age] => 42
        )
)


5.35.9 TableSelect::offset

Copyright 1997-2018 the PHP Documentation Group.

  • TableSelect::offset

    Set limit offset

Description

public mysql_xdevapi\TableSelect mysql_xdevapi\TableSelect::offset(integer position);

Skip given number of rows in result.

Parameters

position

The limit offset.

Return Values

A TableSelect object.

Examples

Example 5.180 mysql_xdevapi\TableSelect::offset example


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

$session->sql("DROP DATABASE IF EXISTS addressbook")->execute();
$session->sql("CREATE DATABASE addressbook")->execute();
$session->sql("CREATE TABLE addressbook.names(name text, age int)")->execute();
$session->sql("INSERT INTO addressbook.names values ('John', 42), ('Sam', 42)")->execute();

$schema = $session->getSchema("addressbook");
$table  = $schema->getTable("names");

$result = $table->select('name', 'age')
  ->limit(1)
  ->offset(1)
  ->execute();

$row = $result->fetchAll();
print_r($row);
?>

   

The above example will output something similar to:


Array
(
    [0] => Array
        (
            [name] => Sam
            [age] => 42
        )
)


5.35.10 TableSelect::orderby

Copyright 1997-2018 the PHP Documentation Group.

  • TableSelect::orderby

    Set select sort criteria

Description

public mysql_xdevapi\TableSelect mysql_xdevapi\TableSelect::orderby(mixed sort_expr,
                                                                    mixed ...);

Sets the order by criteria.

Parameters

sort_expr

The expressions that define the order by criteria. Can be an array with one or more expressions, or a string.

...

Additional sort_expr parameters.

Return Values

A TableSelect object.

Examples

Example 5.181 mysql_xdevapi\TableSelect::orderBy example


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

$schema = $session->getSchema("addressbook");
$table  = $schema->getTable("names");

$result = $table->select('name', 'age')
  ->orderBy('name desc')
  ->execute();

$row = $result->fetchAll();
print_r($row);
?>

   

The above example will output something similar to:


Array
(
    [0] => Array
        (
            [name] => Sam
            [age] => 42
        )
    [1] => Array
        (
            [name] => John
            [age] => 42
        )
)


5.35.11 TableSelect::where

Copyright 1997-2018 the PHP Documentation Group.

  • TableSelect::where

    Set select search condition

Description

public mysql_xdevapi\TableSelect mysql_xdevapi\TableSelect::where(string where_expr);

Sets the search condition to filter.

Parameters

where_expr

Define the search condition to filter documents or records.

Return Values

A TableSelect object.

Examples

Example 5.182 mysql_xdevapi\TableSelect::where example


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

$schema = $session->getSchema("addressbook");
$table  = $schema->getTable("names");

$result = $table->select('name','age')
  ->where('name like :name and age > :age')
  ->bind(['name' => 'John', 'age' => 42])
  ->execute();

$row = $result->fetchAll();
print_r($row);
?>

   

The above example will output something similar to:


Array
(
    [0] => Array
        (
            [name] => John
            [age] => 42
        )
)


5.36 TableUpdate class

Copyright 1997-2018 the PHP Documentation Group.

A statement for record update operations on a Table.

 mysql_xdevapi\TableUpdate {
mysql_xdevapi\TableUpdate , mysql_xdevapi\Executable Methods  public mysql_xdevapi\TableUpdate mysql_xdevapi\TableUpdate::bind(array placeholder_values);
  public mysql_xdevapi\TableUpdate mysql_xdevapi\TableUpdate::execute();
  public mysql_xdevapi\TableUpdate mysql_xdevapi\TableUpdate::limit(integer rows);
  public mysql_xdevapi\TableUpdate mysql_xdevapi\TableUpdate::orderby(mixed orderby_expr,
                                                                      mixed ...);

  public mysql_xdevapi\TableUpdate mysql_xdevapi\TableUpdate::set(string table_field,
                                                                  string expression_or_literal);

  public mysql_xdevapi\TableUpdate mysql_xdevapi\TableUpdate::where(string where_expr);
}

5.36.1 TableUpdate::bind

Copyright 1997-2018 the PHP Documentation Group.

  • TableUpdate::bind

    Bind update query parameters

Description

public mysql_xdevapi\TableUpdate mysql_xdevapi\TableUpdate::bind(array placeholder_values);

Binds a value to a specific placeholder.

Parameters

placeholder_values

The name of the placeholder, and the value to bind, defined as a JSON array.

Return Values

A TableUpdate object.

Examples

Example 5.183 mysql_xdevapi\TableUpdate::bind example


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

$schema = $session->getSchema("addressbook");
$table  = $schema->getTable("names");

$table->update()
  ->set('status', 'admin')
  ->where('name = :name and age > :age')
  ->bind(['name' => 'Bernie', 'age' => 2000])
  ->execute();

?>


5.36.2 TableUpdate::__construct

Copyright 1997-2018 the PHP Documentation Group.

  • TableUpdate::__construct

    TableUpdate constructor

Description

private mysql_xdevapi\TableUpdate::__construct();

Initiated by using the update() method.

Parameters

This function has no parameters.

Examples

Example 5.184 mysql_xdevapi\TableUpdate::__construct example


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

$schema = $session->getSchema("addressbook");
$table  = $schema->getTable("names");

$res = $table->update()
  ->set('level', 3)
  ->where('age > 15 and age < 22')
  ->limit(4)
  ->orderby(['age asc','name desc'])
  ->execute();

?>


5.36.3 TableUpdate::execute

Copyright 1997-2018 the PHP Documentation Group.

  • TableUpdate::execute

    Execute update query

Description

public mysql_xdevapi\TableUpdate mysql_xdevapi\TableUpdate::execute();

Executes the update statement.

Parameters

This function has no parameters.

Return Values

A TableUpdate object.

Examples

Example 5.185 mysql_xdevapi\TableUpdate::execute example


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

$schema = $session->getSchema("addressbook");
$table  = $schema->getTable("names");

$res = $table->update()
  ->set('level', 3)
  ->where('age > 15 and age < 22')
  ->limit(4)
  ->orderby(['age asc','name desc'])
  ->execute();

?>


5.36.4 TableUpdate::limit

Copyright 1997-2018 the PHP Documentation Group.

  • TableUpdate::limit

    Limit update row count

Description

public mysql_xdevapi\TableUpdate mysql_xdevapi\TableUpdate::limit(integer rows);

Set the maximum number of records or documents update.

Parameters

rows

The maximum number of records or documents to update.

Return Values

A TableUpdate object.

Examples

Example 5.186 mysql_xdevapi\TableUpdate::limit example


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

$schema = $session->getSchema("addressbook");
$table  = $schema->getTable("names");

$res = $table->update()
  ->set('level', 3)
  ->where('age > 15 and age < 22')
  ->limit(4)
  ->orderby(['age asc','name desc'])
  ->execute();

?>


5.36.5 TableUpdate::orderby

Copyright 1997-2018 the PHP Documentation Group.

  • TableUpdate::orderby

    Set sorting criteria

Description

public mysql_xdevapi\TableUpdate mysql_xdevapi\TableUpdate::orderby(mixed orderby_expr,
                                                                    mixed ...);

Sets the sorting criteria.

Parameters

orderby_expr

The expressions that define the order by criteria. Can be an array with one or more expressions, or a string.

...

Additional sort_expr parameters.

Return Values

TableUpdate object.

Examples

Example 5.187 mysql_xdevapi\TableUpdate::orderby example


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

$schema = $session->getSchema("addressbook");
$table  = $schema->getTable("names");

$res = $table->update()
  ->set('level', 3)
  ->where('age > 15 and age < 22')
  ->limit(4)
  ->orderby(['age asc','name desc'])
  ->execute();
?>


5.36.6 TableUpdate::set

Copyright 1997-2018 the PHP Documentation Group.

  • TableUpdate::set

    Add field to be updated

Description

public mysql_xdevapi\TableUpdate mysql_xdevapi\TableUpdate::set(string table_field,
                                                                string expression_or_literal);

Updates the column value on records in a table.

Parameters

table_field

The column name to be updated.

expression_or_literal

The value to be set on the specified column.

Return Values

TableUpdate object.

Examples

Example 5.188 mysql_xdevapi\TableUpdate::set example


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

$schema = $session->getSchema("addressbook");
$table  = $schema->getTable("names");

$res = $table->update()
  ->set('level', 3)
  ->where('age > 15 and age < 22')
  ->limit(4)
  ->orderby(['age asc','name desc'])
  ->execute();

?>


5.36.7 TableUpdate::where

Copyright 1997-2018 the PHP Documentation Group.

  • TableUpdate::where

    Set search filter

Description

public mysql_xdevapi\TableUpdate mysql_xdevapi\TableUpdate::where(string where_expr);

Set the search condition to filter.

Parameters

where_expr

The search condition to filter documents or records.

Return Values

A TableUpdate object.

Examples

Example 5.189 mysql_xdevapi\TableUpdate::where example


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

$schema = $session->getSchema("addressbook");
$table  = $schema->getTable("names");

$res = $table->update()
  ->set('level', 3)
  ->where('age > 15 and age < 22')
  ->limit(4)
  ->orderby(['age asc','name desc'])
  ->execute();

?>


5.37 Warning class

Copyright 1997-2018 the PHP Documentation Group.

 mysql_xdevapi\Warning {
mysql_xdevapi\Warning Properties  public message ;
  public level ;
  public code ;
Constructor  private mysql_xdevapi\Warning::__construct();
}

message

level

code

5.37.1 Warning::__construct

Copyright 1997-2018 the PHP Documentation Group.

  • Warning::__construct

    Warning constructor

Description

private mysql_xdevapi\Warning::__construct();

Warning

This function is currently not documented; only its argument list is available.

Parameters

This function has no parameters.

Examples

Example 5.190 mysql_xdevapi\Warning::__construct example


<?php

/* ... */

?>


5.38 XSession class

Copyright 1997-2018 the PHP Documentation Group.

 mysql_xdevapi\XSession {
mysql_xdevapi\XSession Constructor  private mysql_xdevapi\XSession::__construct();
}

5.38.1 XSession::__construct

Copyright 1997-2018 the PHP Documentation Group.

  • XSession::__construct

    Description constructor

Description

private mysql_xdevapi\XSession::__construct();

Warning

This function is currently not documented; only its argument list is available.

Parameters

This function has no parameters.

Examples

Example 5.191 mysql_xdevapi\XSession::__construct example


<?php

/* ... */

?>


';