cvs: peardoc /en/package/database/db intro-execute.xml
| From: | Daniel Convissor | Date: | Tue, 13 Apr 2004 18:30:39 +0000 |
| Subject: | cvs: peardoc /en/package/database/db intro-execute.xml | ||
| Groups: | php.pear.doc | ||
| Request: | Send a blank email to pear-doc+get-3349@lists.php.net to get a copy of this message | ||
danielc Tue Apr 13 14:30:39 2004 EDT
Modified files:
/peardoc/en/package/database/db intro-execute.xml
Log:
Fix leading whitespace/nesting.
http://cvs.php.net/diff.php/peardoc/en/package/database/db/intro-execute.xml?r1=1.17&r2=1.18&ty=u Index: peardoc/en/package/database/db/intro-execute.xml diff -u peardoc/en/package/database/db/intro-execute.xml:1.17 peardoc/en/package/database/db/intro-execute.xml:1.18 --- peardoc/en/package/database/db/intro-execute.xml:1.17 Fri Apr 2 16:16:43 2004 +++ peardoc/en/package/database/db/intro-execute.xml Tue Apr 13 14:30:39 2004 @@ -1,133 +1,133 @@ -<!-- $Revision: 1.17 $ --> +<!-- $Revision: 1.18 $ --> <refentry id="package.database.db.intro-execute"> - <refnamediv> - <refname>Introduction - Prepare & Execute</refname> - <refpurpose>Prepare & Execute/ExecuteMultiple</refpurpose> - </refnamediv> - <refsect1 id="package.database.db.intro-execute.desc"> - &title.desc; - - <refsect2> - <title>Purpose</title> - <para> - <link linkend="package.database.db.db-common.prepare"> - <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. - </para> - <para> - Imagine you want to support two databases with different INSERT - syntax: - <programlisting> - <![CDATA[ + <refnamediv> + <refname>Introduction - Prepare & Execute</refname> + <refpurpose>Prepare & Execute/ExecuteMultiple</refpurpose> + </refnamediv> + <refsect1 id="package.database.db.intro-execute.desc"> + &title.desc; + + <refsect2> + <title>Purpose</title> + <para> + <link linkend="package.database.db.db-common.prepare"> + <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. + </para> + <para> + Imagine you want to support two databases with different INSERT + syntax: + <programlisting> + <![CDATA[ db1: INSERT INTO tbl_name (col1, col2) VALUES (expr1, expr2) db2: INSERT INTO tbl_name SET col1=expr1, col2=expr2 - ]]> - </programlisting> - Correspondending to create multi-lingual scripts you can create - a array with queries like this: - <programlisting role="php"> - <![CDATA[ + ]]> + </programlisting> + Correspondending to create multi-lingual scripts you can create + a array with queries like this: + <programlisting role="php"> + <![CDATA[ $statement['db1']['INSERT_PERSON'] = 'INSERT INTO person (surname, name, age) VALUES (?, ?, ?)'; $statement['db2']['INSERT_PERSON'] = 'INSERT INTO person SET surname=?, name=?, age=?'; - ]]> - </programlisting> - </para> - </refsect2> - - <refsect2> - <title>Prepare</title> - <para> - To use the features above, you have to do two steps. Step one is to - <emphasis>prepare</emphasis> the statement and the second is - to <emphasis>execute</emphasis> it. - </para> - <para> - <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. - <programlisting role="sql"> - <![CDATA[ + ]]> + </programlisting> + </para> + </refsect2> + + <refsect2> + <title>Prepare</title> + <para> + To use the features above, you have to do two steps. Step one is to + <emphasis>prepare</emphasis> the statement and the second is + to <emphasis>execute</emphasis> it. + </para> + <para> + <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. + <programlisting role="sql"> + <![CDATA[ SELECT surname, name, age FROM person 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. - <programlisting role="sql"> - <![CDATA[ + ]]> + </programlisting> + Now check which parameters should be replaced while script + runtime. Substitute this parameters with a placeholder. + <programlisting role="sql"> + <![CDATA[ SELECT surname, name, age FROM person WHERE name = ? AND age < ? - ]]> - </programlisting> - So, thats all! Now you have a generic statement, required by - <link linkend="package.database.db.db-common.prepare"> - <function>prepare</function></link>. - </para> - <para> - <link linkend="package.database.db.db-common.prepare"> - <function>prepare</function></link> can handle different types of - placeholders or wildcards. - <simplelist> - <member> - <literal>?</literal> - (recommended) stands for a scalar - value like strings or numbers, the value will be quoted - depending of the database - </member> - <member> - <literal>!</literal> - stands for a scalar value and - will inserted into the statement <quote>as is</quote>. - </member> - <member> - <literal>&</literal> - requires an existing filename, - the content of this file will be included into the statment - (i.e. for saving binary data of a graphic file in a database) - </member> - </simplelist> - </para> - <para> - Use backslashes to escape placeholder characters if you don't want - them to be interpreted as placeholders: - <programlisting role="sql"> - <![CDATA[ + ]]> + </programlisting> + So, thats all! Now you have a generic statement, required by + <link linkend="package.database.db.db-common.prepare"> + <function>prepare</function></link>. + </para> + <para> + <link linkend="package.database.db.db-common.prepare"> + <function>prepare</function></link> can handle different types of + placeholders or wildcards. + <simplelist> + <member> + <literal>?</literal> - (recommended) stands for a scalar + value like strings or numbers, the value will be quoted + depending of the database + </member> + <member> + <literal>!</literal> - stands for a scalar value and + will inserted into the statement <quote>as is</quote>. + </member> + <member> + <literal>&</literal> - requires an existing filename, + the content of this file will be included into the statment + (i.e. for saving binary data of a graphic file in a database) + </member> + </simplelist> + </para> + <para> + Use backslashes to escape placeholder characters if you don't want + them to be interpreted as placeholders: + <programlisting role="sql"> + <![CDATA[ UPDATE foo SET col=? WHERE col='over \& under' - ]]> - </programlisting> - </para> - </refsect2> - - <refsect2> - <title>Execute/ ExecuteMultiple</title> - <para> - 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>prepare</function></link> and an array - with the values to assign. The array has to be numerically - ordered. The first entry of the array represents the first - wildcard, the second the second wildcard etc. The order is - independent from the used wildcard char. - - <example> - <title>Inserting data into a database</title> - <programlisting role="php"> - <![CDATA[ + ]]> + </programlisting> + </para> + </refsect2> + + <refsect2> + <title>Execute/ ExecuteMultiple</title> + <para> + 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>prepare</function></link> and an array + with the values to assign. The array has to be numerically + ordered. The first entry of the array represents the first + wildcard, the second the second wildcard etc. The order is + independent from the used wildcard char. + + <example> + <title>Inserting data into a database</title> + <programlisting role="php"> + <![CDATA[ // Once you have a valid DB object named $db... $alldata = array(array(1, 'one', 'en'), array(2, 'two', 'to'), @@ -137,34 +137,34 @@ foreach ($alldata as $row) { $db->execute($sth, $row); } - ]]> - </programlisting> - </example> - - In the example the query is done four times: - <programlisting role="sql"> - <![CDATA[ + ]]> + </programlisting> + </example> + + In the example the query is done four times: + <programlisting role="sql"> + <![CDATA[ INSERT INTO numbers VALUES ('1', 'one', 'en') INSERT INTO numbers VALUES ('2', 'two', 'to') INSERT INTO numbers VALUES ('3', 'three', 'tre') INSERT INTO numbers VALUES ('4', 'four', 'fire') - ]]> - </programlisting> - </para> - - <para> - <link linkend="package.database.db.db-common.executemultiple"> - <function>executeMultiple</function></link> works in the same way, but - requires a two dimensional array. So you can avoid the explicit - foreach in the eample above. - - <example> - <title> - Using <function>executeMultiple</function> instead of - <function>execute</function> - </title> - <programlisting role="php"> - <![CDATA[ + ]]> + </programlisting> + </para> + + <para> + <link linkend="package.database.db.db-common.executemultiple"> + <function>executeMultiple</function></link> works in the same way, but + requires a two dimensional array. So you can avoid the explicit + foreach in the eample above. + + <example> + <title> + Using <function>executeMultiple</function> instead of + <function>execute</function> + </title> + <programlisting role="php"> + <![CDATA[ // Once you have a valid DB object named $db... $alldata = array(array(1, 'one', 'en'), array(2, 'two', 'to'), @@ -172,26 +172,26 @@ array(4, 'four', 'fire')); $sth = $db->prepare('INSERT INTO numbers VALUES (?, ?, ?)'); $db->executeMultiple($sth, $alldata); - ]]> - </programlisting> - </example> - </para> - - <para> - The result is the same. If one of the records failed, the - unfinished records will not be executed. - </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. - </para> - - </refsect2> - </refsect1> + ]]> + </programlisting> + </example> + </para> + + <para> + The result is the same. If one of the records failed, the + unfinished records will not be executed. + </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. + </para> + </refsect2> + </refsect1> </refentry> + <!-- Keep this comment at the end of the file Local variables: mode: sgml
http://cvs.php.net/diff.php/peardoc/en/package/database/db/intro-execute.xml?r1=1.17&r2=1.18&ty=u Index: peardoc/en/package/database/db/intro-execute.xml diff -u peardoc/en/package/database/db/intro-execute.xml:1.17 peardoc/en/package/database/db/intro-execute.xml:1.18 --- peardoc/en/package/database/db/intro-execute.xml:1.17 Fri Apr 2 16:16:43 2004 +++ peardoc/en/package/database/db/intro-execute.xml Tue Apr 13 14:30:39 2004 @@ -1,133 +1,133 @@ -<!-- $Revision: 1.17 $ --> +<!-- $Revision: 1.18 $ --> <refentry id="package.database.db.intro-execute"> - <refnamediv> - <refname>Introduction - Prepare & Execute</refname> - <refpurpose>Prepare & Execute/ExecuteMultiple</refpurpose> - </refnamediv> - <refsect1 id="package.database.db.intro-execute.desc"> - &title.desc; - - <refsect2> - <title>Purpose</title> - <para> - <link linkend="package.database.db.db-common.prepare"> - <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. - </para> - <para> - Imagine you want to support two databases with different INSERT - syntax: - <programlisting> - <![CDATA[ + <refnamediv> + <refname>Introduction - Prepare & Execute</refname> + <refpurpose>Prepare & Execute/ExecuteMultiple</refpurpose> + </refnamediv> + <refsect1 id="package.database.db.intro-execute.desc"> + &title.desc; + + <refsect2> + <title>Purpose</title> + <para> + <link linkend="package.database.db.db-common.prepare"> + <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. + </para> + <para> + Imagine you want to support two databases with different INSERT + syntax: + <programlisting> + <![CDATA[ db1: INSERT INTO tbl_name (col1, col2) VALUES (expr1, expr2) db2: INSERT INTO tbl_name SET col1=expr1, col2=expr2 - ]]> - </programlisting> - Correspondending to create multi-lingual scripts you can create - a array with queries like this: - <programlisting role="php"> - <![CDATA[ + ]]> + </programlisting> + Correspondending to create multi-lingual scripts you can create + a array with queries like this: + <programlisting role="php"> + <![CDATA[ $statement['db1']['INSERT_PERSON'] = 'INSERT INTO person (surname, name, age) VALUES (?, ?, ?)'; $statement['db2']['INSERT_PERSON'] = 'INSERT INTO person SET surname=?, name=?, age=?'; - ]]> - </programlisting> - </para> - </refsect2> - - <refsect2> - <title>Prepare</title> - <para> - To use the features above, you have to do two steps. Step one is to - <emphasis>prepare</emphasis> the statement and the second is - to <emphasis>execute</emphasis> it. - </para> - <para> - <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. - <programlisting role="sql"> - <![CDATA[ + ]]> + </programlisting> + </para> + </refsect2> + + <refsect2> + <title>Prepare</title> + <para> + To use the features above, you have to do two steps. Step one is to + <emphasis>prepare</emphasis> the statement and the second is + to <emphasis>execute</emphasis> it. + </para> + <para> + <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. + <programlisting role="sql"> + <![CDATA[ SELECT surname, name, age FROM person 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. - <programlisting role="sql"> - <![CDATA[ + ]]> + </programlisting> + Now check which parameters should be replaced while script + runtime. Substitute this parameters with a placeholder. + <programlisting role="sql"> + <![CDATA[ SELECT surname, name, age FROM person WHERE name = ? AND age < ? - ]]> - </programlisting> - So, thats all! Now you have a generic statement, required by - <link linkend="package.database.db.db-common.prepare"> - <function>prepare</function></link>. - </para> - <para> - <link linkend="package.database.db.db-common.prepare"> - <function>prepare</function></link> can handle different types of - placeholders or wildcards. - <simplelist> - <member> - <literal>?</literal> - (recommended) stands for a scalar - value like strings or numbers, the value will be quoted - depending of the database - </member> - <member> - <literal>!</literal> - stands for a scalar value and - will inserted into the statement <quote>as is</quote>. - </member> - <member> - <literal>&</literal> - requires an existing filename, - the content of this file will be included into the statment - (i.e. for saving binary data of a graphic file in a database) - </member> - </simplelist> - </para> - <para> - Use backslashes to escape placeholder characters if you don't want - them to be interpreted as placeholders: - <programlisting role="sql"> - <![CDATA[ + ]]> + </programlisting> + So, thats all! Now you have a generic statement, required by + <link linkend="package.database.db.db-common.prepare"> + <function>prepare</function></link>. + </para> + <para> + <link linkend="package.database.db.db-common.prepare"> + <function>prepare</function></link> can handle different types of + placeholders or wildcards. + <simplelist> + <member> + <literal>?</literal> - (recommended) stands for a scalar + value like strings or numbers, the value will be quoted + depending of the database + </member> + <member> + <literal>!</literal> - stands for a scalar value and + will inserted into the statement <quote>as is</quote>. + </member> + <member> + <literal>&</literal> - requires an existing filename, + the content of this file will be included into the statment + (i.e. for saving binary data of a graphic file in a database) + </member> + </simplelist> + </para> + <para> + Use backslashes to escape placeholder characters if you don't want + them to be interpreted as placeholders: + <programlisting role="sql"> + <![CDATA[ UPDATE foo SET col=? WHERE col='over \& under' - ]]> - </programlisting> - </para> - </refsect2> - - <refsect2> - <title>Execute/ ExecuteMultiple</title> - <para> - 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>prepare</function></link> and an array - with the values to assign. The array has to be numerically - ordered. The first entry of the array represents the first - wildcard, the second the second wildcard etc. The order is - independent from the used wildcard char. - - <example> - <title>Inserting data into a database</title> - <programlisting role="php"> - <![CDATA[ + ]]> + </programlisting> + </para> + </refsect2> + + <refsect2> + <title>Execute/ ExecuteMultiple</title> + <para> + 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>prepare</function></link> and an array + with the values to assign. The array has to be numerically + ordered. The first entry of the array represents the first + wildcard, the second the second wildcard etc. The order is + independent from the used wildcard char. + + <example> + <title>Inserting data into a database</title> + <programlisting role="php"> + <![CDATA[ // Once you have a valid DB object named $db... $alldata = array(array(1, 'one', 'en'), array(2, 'two', 'to'), @@ -137,34 +137,34 @@ foreach ($alldata as $row) { $db->execute($sth, $row); } - ]]> - </programlisting> - </example> - - In the example the query is done four times: - <programlisting role="sql"> - <![CDATA[ + ]]> + </programlisting> + </example> + + In the example the query is done four times: + <programlisting role="sql"> + <![CDATA[ INSERT INTO numbers VALUES ('1', 'one', 'en') INSERT INTO numbers VALUES ('2', 'two', 'to') INSERT INTO numbers VALUES ('3', 'three', 'tre') INSERT INTO numbers VALUES ('4', 'four', 'fire') - ]]> - </programlisting> - </para> - - <para> - <link linkend="package.database.db.db-common.executemultiple"> - <function>executeMultiple</function></link> works in the same way, but - requires a two dimensional array. So you can avoid the explicit - foreach in the eample above. - - <example> - <title> - Using <function>executeMultiple</function> instead of - <function>execute</function> - </title> - <programlisting role="php"> - <![CDATA[ + ]]> + </programlisting> + </para> + + <para> + <link linkend="package.database.db.db-common.executemultiple"> + <function>executeMultiple</function></link> works in the same way, but + requires a two dimensional array. So you can avoid the explicit + foreach in the eample above. + + <example> + <title> + Using <function>executeMultiple</function> instead of + <function>execute</function> + </title> + <programlisting role="php"> + <![CDATA[ // Once you have a valid DB object named $db... $alldata = array(array(1, 'one', 'en'), array(2, 'two', 'to'), @@ -172,26 +172,26 @@ array(4, 'four', 'fire')); $sth = $db->prepare('INSERT INTO numbers VALUES (?, ?, ?)'); $db->executeMultiple($sth, $alldata); - ]]> - </programlisting> - </example> - </para> - - <para> - The result is the same. If one of the records failed, the - unfinished records will not be executed. - </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. - </para> - - </refsect2> - </refsect1> + ]]> + </programlisting> + </example> + </para> + + <para> + The result is the same. If one of the records failed, the + unfinished records will not be executed. + </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. + </para> + </refsect2> + </refsect1> </refentry> + <!-- Keep this comment at the end of the file Local variables: mode: sgml