cvs: peardoc /en/package/database/db intro-execute.xml intro-fetch.xml intro-query.xml

From: Date: Sun, 18 Apr 2004 15:44:43 +0000
Subject: cvs: peardoc /en/package/database/db intro-execute.xml intro-fetch.xml intro-query.xml
Groups: php.pear.doc 
Request: Send a blank email to pear-doc+get-3618@lists.php.net to get a copy of this message
danielc Sun Apr 18 11:44:43 2004 EDT Modified files: /peardoc/en/package/database/db intro-execute.xml intro-fetch.xml intro-query.xml Log: Clarifications.

http://cvs.php.net/diff.php/peardoc/en/package/database/db/intro-execute.xml?r1=1.24&r2=1.25&ty=u Index: peardoc/en/package/database/db/intro-execute.xml diff -u peardoc/en/package/database/db/intro-execute.xml:1.24 peardoc/en/package/database/db/intro-execute.xml:1.25 --- peardoc/en/package/database/db/intro-execute.xml:1.24 Fri Apr 16 19:29:44 2004 +++ peardoc/en/package/database/db/intro-execute.xml Sun Apr 18 11:44:42 2004 @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="iso-8859-1" ?> -<!-- $Revision: 1.24 $ --> +<!-- $Revision: 1.25 $ --> <refentry id="package.database.db.intro-execute"> <refnamediv> @@ -17,15 +17,16 @@ <function>prepare</function></link> and <link linkend="package.database.db.db-common.execute"> <function>execute*</function></link> - give you more power and flexibilty for query execution. You - can use them, if you have to do more than one equal query - (i.e. adding a list of addresses to a database) or if you want - to support different databases, which have different - implementations of the SQL standard. + give you more power and flexibilty for query execution. + Prepare/execute mode is helpful when you have to run the + same query several times but with different values in it, + such as adding a list of addresses into a database. </para> <para> - Imagine you want to support two databases with different INSERT - syntax: + Another place prepare/execute is useful is supporting + databases which have different SQL syntaxes. + Imagine you want to support two databases with different + <command>INSERT</command> syntax: <programlisting> <![CDATA[ db1: INSERT INTO tbl_name (col1, col2) VALUES (expr1, expr2) @@ -54,22 +55,20 @@ to <emphasis>execute</emphasis> it. </para> <para> + To start out, you need to <link linkend="package.database.db.db-common.prepare"> - <function>Prepare</function></link> has to be called with the generic - statment at least once. It returns a handle for the statment. - </para> - <para> - To create a generic statment is simple. Write the SQL query - as usual, i.e. + <function>prepare</function></link> a generic + SQL statment. Create a generic statment by writing + the SQL query as usual: <programlisting role="sql"> <![CDATA[ SELECT surname, name, age FROM person - WHERE name = 'name_to_find' AND age < 'age_limit' + WHERE name = 'name_to_find' AND age < age_limit ]]> </programlisting> - Now check which parameters should be replaced while script - runtime. Substitute this parameters with a placeholder. + Then substitute <quote>placeholders</quote> for the + literal values which will be provided at run time: <programlisting role="sql"> <![CDATA[ SELECT surname, name, age @@ -77,14 +76,17 @@ WHERE name = ? AND age < ? ]]> </programlisting> - So, thats all! Now you have a generic statement, required by + Then pass this SQL statement to <link linkend="package.database.db.db-common.prepare"> - <function>prepare</function></link>. + <function>prepare</function></link>, which returns + a statement handle to be used when calling + <link linkend="package.database.db.db-common.execute"> + <function>execute</function></link>. </para> <para> <link linkend="package.database.db.db-common.prepare"> <function>prepare</function></link> can handle different types of - placeholders or wildcards. + placeholders (a.k.a. wildcards). <simplelist> <member> <literal>?</literal> - (recommended) stands for a scalar @@ -119,8 +121,9 @@ After preparing the statement, you can execute the query. This means to assign the variables to the prepared statement. To do this, <link linkend="package.database.db.db-common.execute"> - <function>execute</function></link> requires two arguments, the - statement handle of <link linkend="package.database.db.db-common.prepare"> + <function>execute</function></link> requires two arguments: + the statement handle returned by + <link linkend="package.database.db.db-common.prepare"> <function>prepare</function></link> and a scalar or array with the values to assign. </para> @@ -230,9 +233,15 @@ </para> <para> - If <link linkend="package.database.db.db-common.execute"> - <function>execute*</function></link> fails a - &class.db-error;, else &constant.db-ok; will returned. + <link linkend="package.database.db.db-common.execute"> + <function>execute*</function></link> has three + possible returns: + a new &class.db-result; object + for queries that return results (such as + <command>SELECT</command> queries), + &constant.db-ok; for queries that manipulate data (such as + <command>INSERT</command> queries) + or a &class.db-error; object on failure </para> </refsect2> http://cvs.php.net/diff.php/peardoc/en/package/database/db/intro-fetch.xml?r1=1.38&r2=1.39&ty=u Index: peardoc/en/package/database/db/intro-fetch.xml diff -u peardoc/en/package/database/db/intro-fetch.xml:1.38 peardoc/en/package/database/db/intro-fetch.xml:1.39 --- peardoc/en/package/database/db/intro-fetch.xml:1.38 Fri Apr 16 19:16:15 2004 +++ peardoc/en/package/database/db/intro-fetch.xml Sun Apr 18 11:44:42 2004 @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="iso-8859-1" ?> -<!-- $Revision: 1.38 $ --> +<!-- $Revision: 1.39 $ --> <refentry id="package.database.db.intro-fetch"> <refnamediv> @@ -14,7 +14,7 @@ <title>Fetching Individual Rows From Query Results</title> <para> The &class.db-result; object provides two - methods for fetch rows: + methods for fetching data from rows of a result set: <link linkend="package.database.db.db-result.fetchrow"> <function>fetchRow</function></link> and <link linkend="package.database.db.db-result.fetchinto"> @@ -208,9 +208,9 @@ <para> The &class.db-common; object provides several methods that make data retrieval easy by combining - taking the query string you provide and return - the information into various data structures. - These methods include + the processes of running of the query string you provide + and putting the returned information into a + PHP data structure. These methods include <link linkend="package.database.db.db-common.getone"> <function>getOne</function></link>, <link linkend="package.database.db.db-common.getrow"> http://cvs.php.net/diff.php/peardoc/en/package/database/db/intro-query.xml?r1=1.22&r2=1.23&ty=u Index: peardoc/en/package/database/db/intro-query.xml diff -u peardoc/en/package/database/db/intro-query.xml:1.22 peardoc/en/package/database/db/intro-query.xml:1.23 --- peardoc/en/package/database/db/intro-query.xml:1.22 Fri Apr 16 00:45:47 2004 +++ peardoc/en/package/database/db/intro-query.xml Sun Apr 18 11:44:42 2004 @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="iso-8859-1" ?> -<!-- $Revision: 1.22 $ --> +<!-- $Revision: 1.23 $ --> <refentry id="package.database.db.intro-query"> <refnamediv> @@ -9,20 +9,20 @@ <refsect1 id="package.database.db.intro-query.desc"> &title.desc; - <simpara> - To perform a query against a database you have to use the - function <link linkend="package.database.db.db-common.query"> - <function>query</function></link>, that takes the query string - as an argument. On failure you get a - <link linkend="package.database.db.db-error"> - &class.db-error;</link> - object, check it with <link linkend="package.database.db.db.iserror"> - <function>DB::isError</function></link>. On success you get - &constant.db-ok; or - when you set a <command>SELECT</command>-statment a - <link linkend="package.database.db.db-result"> - &class.db-result;</link> object. - </simpara> + <para> + PEAR DB provides several methods for querying databases. + The most direct method is + <link linkend="package.database.db.db-common.query"> + <function>query</function></link>. It takes a SQL query + string as an argument. + There are three possible returns: + a new &class.db-result; object + for queries that return results (such as + <command>SELECT</command> queries), + &constant.db-ok; for queries that manipulate data (such as + <command>INSERT</command> queries) + or a &class.db-error; object on failure. + </para> <example> <title>Doing a query</title>
« previous php.pear.doc (#3618) next »