Improved documentation; and added examples

git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@345514 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
Philip Olson 2018-08-14 21:30:02 +00:00
parent 80b49c63ec
commit 82bb8c2a2b
24 changed files with 499 additions and 101 deletions

View file

@ -32,6 +32,53 @@
</para>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<example>
<title><function>mysql_xdevapi\RowResult::getWarnings</function> example</title>
<programlisting role="php">
<![CDATA[
<?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);
?>
]]>
</programlisting>
&example.outputs.similar;
<screen>
<![CDATA[
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
)
)
]]>
</screen>
</example>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file

View file

@ -32,6 +32,38 @@
</para>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<example>
<title><function>mysql_xdevapi\RowResult::getWarningsCount</function> example</title>
<programlisting role="php">
<![CDATA[
<?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();
?>
]]>
</programlisting>
&example.outputs.similar;
<screen>
<![CDATA[
2
]]>
</screen>
</example>
</refsect1>
</refentry>

View file

@ -49,7 +49,7 @@
</para>
<para>
The MySQL server automatically generates unique <literal>_id</literal> values for
each document, although this can be manually added as well. This value must be
each document (recommended), although this can be manually added as well. This value must be
unique as otherwise the add operation will fail.
</para>
</listitem>
@ -73,31 +73,30 @@
<programlisting role="php">
<![CDATA[
<?php
$schema = $session->getSchema("test");
$coll = $schema->getCollection("test_collection");
$session = mysql_xdevapi\getSession("mysqlx://user:password@localhost");
$session->sql("DROP DATABASE IF EXISTS addressbook")->execute();
$session->sql("CREATE DATABASE addressbook")->execute();
// Add two documents, and _id is generated by the server
$coll->add('{"name": "Marco", "age": 19, "job": "Programmatore"}')->execute();
$coll->add('{"name": "Lonardo", "age": 59, "job": "Paninaro"}')->execute();
$schema = $session->getSchema("addressbook");
$create = $schema->createCollection("people");
// Two two more documents but manually provide _id
// Note: manually adding _id is not recommended, and they must be unique
$coll->add(
["_id" => "1", "name" => "Sakila", "age" => 18, "job" => "Student"],
["_id" => "2", "name" => "Mike", "age" => 39, "job" => "Manager"]
)->execute();
$collection = $schema->getCollection("people");
// Add two more documents using a single JSON object
$res = $coll->add(
'{"name": "Marco",
"jobs": [{"title":"Mangiatore","Salary":1000},{"title":"Ciarlatano","Salary":12000}],
"hobby": ["Spavare","Soffiare Minestrine"], "code":0}',
'{"name": "Lucrezia",
"jobs": [{"title":"Urlatrice","Salary":2000},{"title":"Parlatrice","Salary":3400}],
"hobby": ["Cucinare","Guidare auto sportive","Cavalcare"], "code":1}')->execute();
// Add two documents
$collection->add('{"name": "Fred", "age": 21, "job": "Construction"}')->execute();
$collection->add('{"name": "Wilma", "age": 23, "job": "Teacher"}')->execute();
// Fetch a list of generated ID's and print
$ids = $res->getGeneratedIds();
// 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);
?>
]]>
@ -107,9 +106,10 @@ print_r($ids);
<![CDATA[
Array
(
[0] => 00005ad4d63c000000000000000a
[1] => 00005ad4d63c000000000000000b
)]]>
[0] => 00005b6b53610000000000000056
[1] => 00005b6b53610000000000000057
)
]]>
</screen>
</example>
</refsect1>

View file

@ -57,7 +57,7 @@
<programlisting role="php">
<![CDATA[
<?php
$session = mysql_xdevapi\getSession("mysqlx://root:foofoofoo@localhost");
$session = mysql_xdevapi\getSession("mysqlx://user:password@localhost");
$session->sql("DROP DATABASE IF EXISTS addressbook")->execute();
$session->sql("CREATE DATABASE addressbook")->execute();

View file

@ -38,7 +38,7 @@
<programlisting role="php">
<![CDATA[
<?php
$session = mysql_xdevapi\getSession("mysqlx://root:foofoofoo@localhost");
$session = mysql_xdevapi\getSession("mysqlx://user:password@localhost");
$session->sql("DROP DATABASE IF EXISTS addressbook")->execute();
$session->sql("CREATE DATABASE addressbook")->execute();

View file

@ -38,7 +38,7 @@
<programlisting role="php">
<![CDATA[
<?php
$session = mysql_xdevapi\getSession("mysqlx://root:foofoofoo@localhost");
$session = mysql_xdevapi\getSession("mysqlx://user:password@localhost");
$session->sql("DROP DATABASE IF EXISTS addressbook")->execute();
$session->sql("CREATE DATABASE addressbook")->execute();

View file

@ -47,17 +47,37 @@
<programlisting role="php">
<![CDATA[
<?php
$session = mysql_xdevapi\getSession("mysqlx://user:password@localhost");
$res = $table->select('name','age')->where('name like :name and age > :age')
->bind(['name' => 'Tierney', 'age' => 34])->orderBy('age desc')->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])
->execute();
$row = $result->fetchAll();
print_r($row);
?>
]]>
</programlisting>
&example.outputs.similar;
<screen>
<![CDATA[
Array
(
[0] => Array
(
[name] => John
[age] => 42
)
)
]]>
</screen>
</example>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file

View file

@ -14,7 +14,8 @@
<void />
</constructorsynopsis>
<para>
An object returned by the select() method; use execute() to
execute the query.
</para>
</refsect1>
@ -24,18 +25,6 @@
&no.function.parameters;
</refsect1>
<!-- Return values commented out, as constructors generally don't return a
value. Uncomment this if you do need a return values section (for
example, because there's also a procedural version of the method).
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
</para>
</refsect1>
-->
<refsect1 role="examples">
&reftitle.examples;
<example>
@ -43,16 +32,44 @@
<programlisting role="php">
<![CDATA[
<?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);
?>
]]>
</programlisting>
</example>
</programlisting>
&example.outputs.similar;
<screen>
<![CDATA[
Array
(
[0] => Array
(
[name] => John
[age] => 42
)
)
]]>
</screen>
</example>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file

View file

@ -14,7 +14,7 @@
<void />
</methodsynopsis>
<para>
Execute the statement.
Execute the select statement by chaining it with the execute() method.
</para>
</refsect1>
@ -38,16 +38,37 @@
<programlisting role="php">
<![CDATA[
<?php
$session = mysql_xdevapi\getSession("mysqlx://user:password@localhost");
$res = $table->select('name','age')->where('name like \'P%\' or name like\'C%\'')->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();
?>
]]>
</programlisting>
&example.outputs.similar;
<screen>
<![CDATA[
Array
(
[0] => Array
(
[name] => John
[age] => 42
)
)
]]>
</screen>
</example>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file

View file

@ -47,16 +47,47 @@
<programlisting role="php">
<![CDATA[
<?php
$session = mysql_xdevapi\getSession("mysqlx://user:password@localhost");
$res = $table->select('count(b) as bb')->groupBy('b')->orderBy('b asc')->execute();
$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);
?>
]]>
</programlisting>
&example.outputs.similar;
<screen>
<![CDATA[
Array
(
[0] => Array
(
[count] => 1
[age] => 31
)
[1] => Array
(
[count] => 2
[age] => 42
)
)
]]>
</screen>
</example>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file

View file

@ -14,9 +14,8 @@
<methodparam><type>string</type><parameter>sort_expr</parameter></methodparam>
</methodsynopsis>
<para>
Sets a condition for records to consider in agregate function operations.
Sets a condition for records to consider in aggregate function operations.
</para>
</refsect1>
<refsect1 role="parameters">
@ -26,7 +25,7 @@
<term><parameter>sort_expr</parameter></term>
<listitem>
<para>
A condition on the agregate functions used on the grouping criteria.
A condition on the aggregate functions used on the grouping criteria.
</para>
</listitem>
</varlistentry>
@ -47,20 +46,43 @@
<programlisting role="php">
<![CDATA[
<?php
$session = mysql_xdevapi\getSession("mysqlx://user:password@localhost");
$sel = $table->select(['age as age_group', 'count(name) as cnt'])->groupBy('age_group');
$sel = $sel->where("age > 11 and 1 < 2 and 40 between 30 and 900");
$sel = $sel->having('cnt > 1');
$sel = $sel->orderBy('age_group desc');
$res = $sel->limit(2)->offset(1)->execute();
$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);
?>
]]>
</programlisting>
&example.outputs.similar;
<screen>
<![CDATA[
Array
(
[0] => Array
(
[count] => 2
[age] => 42
)
)
]]>
</screen>
</example>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file

View file

@ -40,6 +40,43 @@
</para>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<example>
<title><function>mysql_xdevapi\TableSelect::limit</function> example</title>
<programlisting role="php">
<![CDATA[
<?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);
?>
]]>
</programlisting>
&example.outputs.similar;
<screen>
<![CDATA[
Array
(
[0] => Array
(
[name] => John
[age] => 42
)
)
]]>
</screen>
</example>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file

View file

@ -53,18 +53,45 @@
<programlisting role="php">
<![CDATA[
<?php
$session = mysql_xdevapi\getSession("mysqlx://user:password@localhost");
$schema = $session->getSchema("addressbook");
$table = $schema->getTable("names");
$session->startTransaction();
$res = $table->select('ordinal', 'n')->where("ordinal like '1'")->lockExclusive(MYSQLX_LOCK_NOWAIT)->execute();
$result = $table->select('name', 'age')
->lockExclusive(MYSQLX_LOCK_NOWAIT)
->execute();
$session->commit();
$row = $result->fetchAll();
print_r($row);
?>
]]>
</programlisting>
&example.outputs.similar;
<screen>
<![CDATA[
Array
(
[0] => Array
(
[name] => John
[age] => 42
)
[1] => Array
(
[name] => Sam
[age] => 42
)
)
]]>
</screen>
</example>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file

View file

@ -53,18 +53,45 @@
<programlisting role="php">
<![CDATA[
<?php
$session = mysql_xdevapi\getSession("mysqlx://user:password@localhost");
$schema = $session->getSchema("addressbook");
$table = $schema->getTable("names");
$session->startTransaction();
$res = $table->select('ordinal', 'n')->where("ordinal like '3'")->lockShared(MYSQLX_LOCK_NOWAIT)->execute();
$result = $table->select('name', 'age')
->lockShared(MYSQLX_LOCK_NOWAIT)
->execute();
$session->commit();
$row = $result->fetchAll();
print_r($row);
?>
]]>
</programlisting>
&example.outputs.similar;
<screen>
<![CDATA[
Array
(
[0] => Array
(
[name] => John
[age] => 42
)
[1] => Array
(
[name] => Sam
[age] => 42
)
)
]]>
</screen>
</example>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file

View file

@ -47,12 +47,39 @@
<programlisting role="php">
<![CDATA[
<?php
$session = mysql_xdevapi\getSession("mysqlx://user:password@localhost");
$res = $table->select()->where("name = :name")->orderby("age DESC")->limit(2)->bind(['name' => 'Tierney'])->execute();
$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);
?>
]]>
</programlisting>
&example.outputs.similar;
<screen>
<![CDATA[
Array
(
[0] => Array
(
[name] => Sam
[age] => 42
)
)
]]>
</screen>
</example>
</refsect1>

View file

@ -53,16 +53,42 @@
<refsect1 role="examples">
&reftitle.examples;
<example>
<title><function>mysql_xdevapi\TableSelect::orderby</function> example</title>
<title><function>mysql_xdevapi\TableSelect::orderBy</function> example</title>
<programlisting role="php">
<![CDATA[
<?php
$session = mysql_xdevapi\getSession("mysqlx://user:password@localhost");
$res = $table->select(['name','age'])->where('name in (\'Cassidy\',\'Polly\')')->orderBy(['age desc','name asc'])->execute();
$schema = $session->getSchema("addressbook");
$table = $schema->getTable("names");
$result = $table->select('name', 'age')
->orderBy('name desc')
->execute();
$row = $result->fetchAll();
print_r($row);
?>
]]>
</programlisting>
&example.outputs.similar;
<screen>
<![CDATA[
Array
(
[0] => Array
(
[name] => Sam
[age] => 42
)
[1] => Array
(
[name] => John
[age] => 42
)
)
]]>
</screen>
</example>
</refsect1>

View file

@ -47,16 +47,37 @@
<programlisting role="php">
<![CDATA[
<?php
$session = mysql_xdevapi\getSession("mysqlx://user:password@localhost");
$res = $table->select('name as nm','age as ag')->where('age > 34')->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])
->execute();
$row = $result->fetchAll();
print_r($row);
?>
]]>
</programlisting>
&example.outputs.similar;
<screen>
<![CDATA[
Array
(
[0] => Array
(
[name] => John
[age] => 42
)
)
]]>
</screen>
</example>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file

View file

@ -26,7 +26,8 @@
<term><parameter>placeholder_values</parameter></term>
<listitem>
<para>
The name of the placeholder, and the value to bind.
The name of the placeholder, and the value to bind, defined
as a JSON array.
</para>
</listitem>
</varlistentry>
@ -47,8 +48,16 @@
<programlisting role="php">
<![CDATA[
<?php
$session = mysql_xdevapi\getSession("mysqlx://user:password@localhost");
$res = $table->update()->set('name', 'Alfonso')->where('name = :name and age > 2000')->bind(['name' => 'Oracila'])->execute();
$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();
?>
]]>
@ -56,7 +65,6 @@ $res = $table->update()->set('name', 'Alfonso')->where('name = :name and age > 2
</example>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file

View file

@ -14,7 +14,7 @@
<void />
</constructorsynopsis>
<para>
Initiated by using the update() method.
</para>
</refsect1>
@ -24,18 +24,6 @@
&no.function.parameters;
</refsect1>
<!-- Return values commented out, as constructors generally don't return a
value. Uncomment this if you do need a return values section (for
example, because there's also a procedural version of the method).
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
</para>
</refsect1>
-->
<refsect1 role="examples">
&reftitle.examples;
<example>
@ -43,13 +31,22 @@
<programlisting role="php">
<![CDATA[
<?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();
?>
]]>
</programlisting>
</example>
</programlisting>
</example>
</refsect1>

View file

@ -38,8 +38,17 @@
<programlisting role="php">
<![CDATA[
<?php
$session = mysql_xdevapi\getSession("mysqlx://user:password@localhost");
$res = $table->update()->set('age',69)->where('age > 15 and age < 22')->limit(4)->orderby(['age asc','name desc'])->execute();
$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();
?>
]]>
@ -47,7 +56,6 @@ $res = $table->update()->set('age',69)->where('age > 15 and age < 22')->limit(4)
</example>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file

View file

@ -47,9 +47,17 @@
<programlisting role="php">
<![CDATA[
<?php
$session = mysql_xdevapi\getSession("mysqlx://user:password@localhost");
$upd = $table->update()->orderBy('age desc')->set('age', 1)->set('name', 'Toddler');
$res = $upd->where('age > :param1 and age < :param2')->bind(['param1' => 500, 'param2' => 1901])->limit(2)->execute();
$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();
?>
]]>
@ -57,7 +65,6 @@ $res = $upd->where('age > :param1 and age < :param2')->bind(['param1' => 500, 'p
</example>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file

View file

@ -57,16 +57,23 @@
<programlisting role="php">
<![CDATA[
<?php
$session = mysql_xdevapi\getSession("mysqlx://user:password@localhost");
$res = $table->update()->set('age',69)->where('age > 15 and age < 22')->limit(4)->orderby(['age asc','name desc'])->execute();
$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();
?>
]]>
</programlisting>
</example>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file

View file

@ -56,8 +56,17 @@
<programlisting role="php">
<![CDATA[
<?php
$session = mysql_xdevapi\getSession("mysqlx://user:password@localhost");
$res = $table->update()->set('age',69)->where('age > 15 and age < 22')->limit(4)->orderby(['age asc','name desc'])->execute();
$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();
?>
]]>
@ -65,7 +74,6 @@ $res = $table->update()->set('age',69)->where('age > 15 and age < 22')->limit(4)
</example>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file

View file

@ -47,8 +47,17 @@
<programlisting role="php">
<![CDATA[
<?php
$session = mysql_xdevapi\getSession("mysqlx://user:password@localhost");
$res = $table->update()->set('doc', '{"_id": "7", "name": "John", "job": "Smith"}')->where('_id = "7"')->execute();
$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();
?>
]]>
@ -56,7 +65,6 @@ $res = $table->update()->set('doc', '{"_id": "7", "name": "John", "job": "Smith"
</example>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file