Documented the Table object

git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@345487 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
Philip Olson 2018-08-13 21:02:29 +00:00
parent 3190b97528
commit 80b49c63ec
11 changed files with 173 additions and 46 deletions

View file

@ -14,7 +14,7 @@
<void />
</constructorsynopsis>
<para>
Construct a table object.
</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,14 @@
<programlisting role="php">
<![CDATA[
<?php
$session = mysql_xdevapi\getSession("mysqlx://user:password@localhost");
/* ... */
$schema = $session->getSchema("addressbook");
$table = $schema->getTable("names");
?>
]]>
</programlisting>
</example>
</programlisting>
</example>
</refsect1>

View file

@ -27,7 +27,7 @@
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
The total of rows in the table.
The total number of rows in the table.
</para>
</refsect1>
@ -38,16 +38,29 @@
<programlisting role="php">
<![CDATA[
<?php
$session = mysql_xdevapi\getSession("mysqlx://user:password@localhost");
$rowsCount = $table->count();
$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());
?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
int(2)
]]>
</screen>
</example>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file

View file

@ -16,7 +16,6 @@
<para>
Deletes rows from a table.
</para>
</refsect1>
<refsect1 role="parameters">
@ -27,7 +26,7 @@
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
A TableDelete object
A TableDelete object; use the execute() method to execute the delete query.
</para>
</refsect1>
@ -38,16 +37,23 @@
<programlisting role="php">
<![CDATA[
<?php
$session = mysql_xdevapi\getSession("mysqlx://user:password@localhost");
$table->delete()->where("name = :name")->orderby("id DESC")->limit(2)->bind(['name' => 'Cassidy'])->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', 33)")->execute();
$schema = $session->getSchema("addressbook");
$table = $schema->getTable("names");
$table->delete()->where("name = :name")->orderby("age DESC")->limit(1)->bind(['name' => 'John'])->execute();
?>
]]>
</programlisting>
</example>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file

View file

@ -16,7 +16,6 @@
<para>
Verifies if this table exists in the database.
</para>
</refsect1>
<refsect1 role="parameters">
@ -38,16 +37,31 @@
<programlisting role="php">
<![CDATA[
<?php
$session = mysql_xdevapi\getSession("mysqlx://user:password@localhost");
$existInDb = $table->existsInDatabase();
$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.";
}
?>
]]>
</programlisting>
&example.outputs.similar;
<screen>
<![CDATA[
Yes, this table still exists in the session's schema.
]]>
</screen>
</example>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file

View file

@ -38,12 +38,26 @@
<programlisting role="php">
<![CDATA[
<?php
$session = mysql_xdevapi\getSession("mysqlx://user:password@localhost");
$tabName = $table->getName();
$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());
?>
]]>
</programlisting>
&example.outputs.similar;
<screen>
<![CDATA[
string(5) "names"
]]>
</screen>
</example>
</refsect1>

View file

@ -38,16 +38,32 @@
<programlisting role="php">
<![CDATA[
<?php
$session = mysql_xdevapi\getSession("mysqlx://user:password@localhost");
$schema = $table->getSchema();
$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());
?>
]]>
</programlisting>
&example.outputs.similar;
<screen>
<![CDATA[
object(mysql_xdevapi\Schema)#9 (1) {
["name"]=>
string(11) "addressbook"
}
]]>
</screen>
</example>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file

View file

@ -38,13 +38,29 @@
<programlisting role="php">
<![CDATA[
<?php
$session = mysql_xdevapi\getSession("mysqlx://user:password@localhost");
$session = $table->getSession();
$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());
?>
]]>
</programlisting>
&example.outputs.similar;
<screen>
<![CDATA[
object(mysql_xdevapi\Session)#9 (0) {
}
]]>
</screen>
</example>
</refsect1>

View file

@ -15,7 +15,7 @@
<methodparam choice="opt"><type>mixed</type><parameter>...</parameter></methodparam>
</methodsynopsis>
<para>
Creates a new TableInsert object.
Inserts rows into a table.
</para>
</refsect1>
@ -46,7 +46,7 @@
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
A TableInsert object.
A TableInsert object; use the execute() method to execute the insert statement.
</para>
</refsect1>
@ -57,16 +57,23 @@
<programlisting role="php">
<![CDATA[
<?php
$session = mysql_xdevapi\getSession("mysqlx://root:foofoofoo@localhost");
$table->insert("name", "age")->values(["Sakila", 128],["Sakila", 512])->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', 33)")->execute();
$schema = $session->getSchema("addressbook");
$table = $schema->getTable("names");
$table->insert("name", "age")->values(["Suzanne", 31],["Julie", 43]);
?>
]]>
</programlisting>
</example>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file

View file

@ -38,12 +38,30 @@
<programlisting role="php">
<![CDATA[
<?php
$session = mysql_xdevapi\getSession("mysqlx://root:foofoofoo@localhost");
$isView = $table->isView();
$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.";
}
?>
]]>
</programlisting>
&example.outputs;
<screen>
<![CDATA[
int(2)
]]>
</screen>
</example>
</refsect1>

View file

@ -15,7 +15,7 @@
<methodparam choice="opt"><type>mixed</type><parameter>...</parameter></methodparam>
</methodsynopsis>
<para>
Creates a new TableSelect object.
Fetches data from a table.
</para>
</refsect1>
@ -46,27 +46,54 @@
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
TableSelect object.
A TableSelect object; use the execute() method to execute the
select and return a RowResult object.
</para>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<example>
<title><function>mysql_xdevapi\Table::select</function> example</title>
<title><function>mysql_xdevapi\Table::count</function> example</title>
<programlisting role="php">
<![CDATA[
<?php
$session = mysql_xdevapi\getSession("mysqlx://user:password@localhost");
$res = $table->select(['age', 'name'])->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', 33)")->execute();
?>
$schema = $session->getSchema("addressbook");
$table = $schema->getTable("names");
$row = $table->select('name', 'age')->execute()->fetchAll();
print_r($row);
]]>
</programlisting>
&example.outputs.similar;
<screen>
<![CDATA[
Array
(
[0] => Array
(
[name] => John
[age] => 42
)
[1] => Array
(
[name] => Sam
[age] => 33
)
)
]]>
</screen>
</example>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file

View file

@ -14,7 +14,7 @@
<void />
</methodsynopsis>
<para>
Creates a new TableUpdate object.
Updates columns in a table.
</para>
</refsect1>
@ -27,7 +27,7 @@
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
A TableUpdate object.
A TableUpdate object; use the execute() method to execute the update statement.
</para>
</refsect1>
@ -38,16 +38,23 @@
<programlisting role="php">
<![CDATA[
<?php
$session = mysql_xdevapi\getSession("mysqlx://root:foofoofoo@localhost");
$res = $table->update()->set('age',69)->where('age > 15 and age < 22')->limit(4)->orderby(['age asc','name desc'])->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', 33)")->execute();
$schema = $session->getSchema("addressbook");
$table = $schema->getTable("names");
$table->update()->set('age',34)->where('name = "Sam"')->limit(1)->execute();
?>
]]>
</programlisting>
</example>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file