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

From: Date: Tue, 21 Jun 2005 14:15:56 +0000
Subject: cvs: peardoc /en/package/database/db-dataobject intro-purpose.xml
Groups: php.pear.doc 
Request: Send a blank email to pear-doc+get-6380@lists.php.net to get a copy of this message
alexmerz Tue Jun 21 10:15:56 2005 EDT Modified files: /peardoc/en/package/database/db-dataobject intro-purpose.xml Log: fix #4648 http://cvs.php.net/diff.php/peardoc/en/package/database/db-dataobject/intro-purpose.xml?r1=1.15&r2=1.16&ty=u Index: peardoc/en/package/database/db-dataobject/intro-purpose.xml diff -u peardoc/en/package/database/db-dataobject/intro-purpose.xml:1.15 peardoc/en/package/database/db-dataobject/intro-purpose.xml:1.16 --- peardoc/en/package/database/db-dataobject/intro-purpose.xml:1.15 Fri Jan 14 02:58:29 2005 +++ peardoc/en/package/database/db-dataobject/intro-purpose.xml Tue Jun 21 10:15:55 2005 @@ -1,93 +1,91 @@ -<!-- $Revision: 1.15 $ --> +<?xml version="1.0" encoding="iso-8859-1" ?> +<!-- $Revision: 1.16 $ --> +<!-- EN-Revision: 1.15 --> <refentry id="package.database.db-dataobject.intro-purpose"> - <refnamediv> - <refname>Introduction</refname> - <refpurpose> - What <classname>DB_DataObject</classname> can do - </refpurpose> - </refnamediv> - <refsect1> - <title>Introduction</title> - - <warning> + <refnamediv> + <refname>Einführung</refname> + <refpurpose>Was <classname>DB_DataObject</classname> kann</refpurpose> + </refnamediv> + <refsect1> + <title>Einführung</title> + <warning> + <para> + Zend Optimizer: Aufgrund eines Bugs im Optimizer, muss der Optimierungs-Level reduziert werden + oder die Konstante <constant>DB_DATAOBJECT_NO_OVERLOAD</constant> auf <literal>0</literal> + gesetzt werden. Ansonsten kann PHP einen Segmentation Fault auslösen. + </para> <para> - Zend Optimizer: due to a bug in the optimizer, you will have to either reduce the - optimization level, or define the constant DB_DATAOBJECT_NO_OVERLOAD = 0 - otherwise PHP may segfault - </para> <para> - Pass by Reference, due to a unfixable bug in PHP4, you can not use overload with pass-by-reference arguments - (It works OK in PHP5), If you need pass-by-reference, define the constant DB_DATAOBJECT_NO_OVERLOAD = 0 + Übergabe-per-Referenze (pass by reference): Aufgrund eines nicht korregierbaren Fehlers in PHP 4 + kann die Overload-Funktion mit Argumenten, die per Referenz übergeben werden, nicht benutzt werden. + In PHP 5 gibt es keine Probleme damit. Wenn Sie die Funktion aber auch unter PHP 4 benutzen wollen, dann + müssen Sie gleichfalls die Konstante <constant>DB_DATAOBJECT_NO_OVERLOAD</constant> auf <literal>0</literal> + setzen. </para> </warning> - - <para> - <classname>DB_DataObject</classname> is a SQL Builder and Data Modeling Layer - built on top of PEAR::&class.db;. Its main purpose is to - </para> - <para> - <itemizedlist> - <listitem> - <simpara>Build SQL and execute statements based on the objects variables.</simpara> - </listitem> - <listitem> - <simpara>Group source code around the data that they relate to.</simpara> - </listitem> - <listitem> - <simpara>Provide a simple consistent API to access and manipulate that data.</simpara> - </listitem> - </itemizedlist> - </para> - - <para> - So what does that mean in english? Well, if you look around at some of the better written PHP - applications and frameworks out there, you will notice a common approach to using classes to - wrap access to database tables or groups. The prime example of this is the person object, which would - frequently look something like this. - - <example> - <title>A Classic Data Object or Container</title> - <programlisting role="php"> + <para> + <classname>DB_DataObject</classname> erzeugt SQL und bildet eine Datenmodellschicht auf + der Basis von PEAR::&class.db;. Sein Zweck ist: + <itemizedlist> + <listitem> + <simpara>SQL-Anweisungen zu erzeugen und auszuführen basierend auf Objektvariablen.</simpara> + </listitem> + <listitem> + <simpara>Quellcode und die sich darauf beziehenden Daten zusammenzufassen.</simpara> + </listitem> + <listitem> + <simpara>eine einfache und konsistente API zum Zugriff und zur Bearbeitung von Daten zu bieten.</simpara> + </listitem> + </itemizedlist> + </para> + <para> + Was heisst das praktisch gesprochen? Wenn man sich gute geschriebene PHP-Programme und -Frameworks + anschaut, dann findet man häufig ein durchgängiges Konzept zur Kapselung des Zugriffs auf Datenbank-tabellen. + Ein klassisches Beispiel ist ein Objekt Person, dass üblicherweise so aussieht: + <example> + <title>Ein klassisches Datenobjekt oder -container I</title> + <programlisting role="php"> <![CDATA[ - + class MyPerson { - + // gets an array of data about the seleted person function getPerson($id) { global $db; $result = $db->query("SELECT * FROM person WHERE id=$id"); return $result->fetchRow(); } - + // example of checking a password. function checkPassword($username,$password) { global $db; $db->query("SELECT username FROM person WHERE username='$username' AND password = '$password'"); return $result->fetchRow(); } - + } - + // get the persons details.. $array = MyPerson::getPerson(12); - + ]]> - </programlisting></example> - </para> - <para> - The key benifit of this approach is that you are grouping similar actions on a single table in one place, and are - more likely to spot duplicated code (eg. two methods that do similar things). You will also notice the global $db variable - used here - the fact is that most of the time you will use a common database connection for all your classes, so how should this - be dealt with? - </para> - <para> - The next step on this road is to use the objects variables as a storage mechanism. - - <example> - <title>A Classic Data Object or Container</title> - <programlisting role="php"> + </programlisting> + </example> + </para> + <para> + Der Reiz des Ansatzes ist das Zusammenfassen ähnlicher Aktionen auf eine einzelne Tabelle an einem + Ort und die Vermeidung duplizierten Codes (z.B. zweier Methode, die das Gleiche tun). Weiterhin + bemerkt man die hier benutzte globale Variable <parameter>$db</parameter> - schließlich wird + die meiste Zeit nur eine einzelne Datenbankverbindung in allen Klassen benutzt, dass muss + irgendwie gehandhabt werden. + </para> + <para> + Der nächste Schritt ist die Verwendung von Objektvariablen zur Speicherung. + <example> + <title>Ein klassisches Datenobjekt oder -container II</title> + <programlisting role="php"> <![CDATA[ - + class MyPerson { var $id; @@ -106,7 +104,7 @@ } function getAge() { - $age = date('Y') - date('Y',$this->birthDate); + return date('Y') - date('Y',$this->birthDate); } } @@ -117,15 +115,16 @@ ]]> - </programlisting></example> - </para> - <para> - As you can see, the current row of data is now stored in the Data Container, and additional methods can be added to manipulate - the data in the object or even call other related objects (eg. tables relationships in databases) - </para> - - <para> - As a next step, why not utilize the member variables to perform searches or gets on the database. + </programlisting> + </example> + </para> + <para> + Wie man sieht, wird der aktuelle Datensatz im Datencontainer gespeichert, und zusätzliche Methoden können + deshalb hinzugefügt werden, um Daten innerhalb des Objektes zu bearbeiten; oder wiederum andere + diesbezügliche Objekte aufzurufen (z.B.: Beziehungstabellen in Datenbanken). + </para> + <para> + As a next step, why not utilize the member variables to perform searches or gets on the database.

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