cvs: peardoc /en/package/database/db-dataobject/db-dataobject count.xml

From: Date: Wed, 06 Jul 2005 06:06:37 +0000
Subject: cvs: peardoc /en/package/database/db-dataobject/db-dataobject count.xml
Groups: php.pear.doc 
Request: Send a blank email to pear-doc+get-6462@lists.php.net to get a copy of this message
alan_k Wed Jul 6 02:06:37 2005 EDT Modified files: /peardoc/en/package/database/db-dataobject/db-dataobject count.xml Log: update count docs to current state - countWhat argument http://cvs.php.net/diff.php/peardoc/en/package/database/db-dataobject/db-dataobject/count.xml?r1=1.5&r2=1.6&ty=u Index: peardoc/en/package/database/db-dataobject/db-dataobject/count.xml diff -u peardoc/en/package/database/db-dataobject/db-dataobject/count.xml:1.5 peardoc/en/package/database/db-dataobject/db-dataobject/count.xml:1.6 --- peardoc/en/package/database/db-dataobject/db-dataobject/count.xml:1.5 Mon Mar 10 17:27:41 2003 +++ peardoc/en/package/database/db-dataobject/db-dataobject/count.xml Wed Jul 6 02:06:36 2005 @@ -1,4 +1,4 @@ -<!-- $Revision: 1.5 $ --> +<!-- $Revision: 1.6 $ --> <refentry id="package.database.db-dataobject.db-dataobject.count"> <refnamediv> <refname>-&gt;count()</refname> @@ -9,9 +9,8 @@ <funcprototype> <funcdef>int <function>$DB_DataObject-&gt;count</function></funcdef> - - - <paramdef></paramdef> + <paramdef>string | boolean <parameter><optional>$countWhat | $whereAddOnly</optional></parameter></paramdef> + <paramdef>boolean <parameter><optional>$whereAddOnly</optional></parameter></paramdef> </funcprototype> </funcsynopsis> @@ -37,12 +36,20 @@ <listitem> <para> + <parameter>string $countWhat</parameter> - by default count will count on the primary key, + if you need to count something else, or count DISTINCT set this value. + + </para> + </listitem> + + <listitem> + <para> <parameter>boolean $useWhereAddOnly</parameter> - use only the whereAdd conditions (by default, count will only use both the object settings and the whereAdd conditions) </para> - </listitem> - + </listitem> + </itemizedlist> </para> </refsect1> @@ -73,12 +80,28 @@ <title>Simple find and fetch of data based on Object Vars</title> <programlisting role="php"> <![CDATA[ -$person = new DataObjects_Person; +<?php -$person->whereAdd('name like '%test%'); +/* using property values */ +$person = new DataObjects_Person; +$person->name = "test" $total = $person->count(); - echo "There are {$total} people with a name like test"; + +/* using countWhat */ +$person = new DataObjects_Person; +$total = $person->count('DISTINCT name'); +echo "There are {$total} names in the database"; + + +/* using whereOnly */ +$person = new DataObjects_Person; +$person->name = "test"; +$person->whereAdd("name like '%test%"); +$total = $person->count(true); +echo "There are {$total} names in the database"; + +?> ]]> </programlisting> </example> @@ -86,7 +109,19 @@ <title>Resulting SQL </title> <programlisting> <![CDATA[ -SELECT count(id) FROM person WHERE name like '%test%' +SELECT count(person.id) AS DATAOBJECT_NUM + FROM person + WHERE person.name = 'test'; + +SELECT count(DISTINCT name) AS DATAOBJECT_NUM + FROM person; + +SELECT count(person.id) AS DATAOBJECT_NUM + FROM person + WHERE name like '%test%'; + + + ]]> </programlisting> </example>

« previous php.pear.doc (#6462) next »