cvs: peardoc /en/package/database/db/db-common autoexecute.xml autoprepare.xml

From: Date: Tue, 13 Jul 2004 15:29:43 +0000
Subject: cvs: peardoc /en/package/database/db/db-common autoexecute.xml autoprepare.xml
Groups: php.pear.doc 
Request: Send a blank email to pear-doc+get-4588@lists.php.net to get a copy of this message
danielc Tue Jul 13 11:29:43 2004 EDT Modified files: /peardoc/en/package/database/db/db-common autoexecute.xml autoprepare.xml Log: * Clarify need to escape and quote items in $where parameter. * Provide examples to distinguish between insert and update mode. http://cvs.php.net/diff.php/peardoc/en/package/database/db/db-common/autoexecute.xml?r1=1.31&r2=1.32&ty=u Index: peardoc/en/package/database/db/db-common/autoexecute.xml diff -u peardoc/en/package/database/db/db-common/autoexecute.xml:1.31 peardoc/en/package/database/db/db-common/autoexecute.xml:1.32 --- peardoc/en/package/database/db/db-common/autoexecute.xml:1.31 Sat May 1 16:31:29 2004 +++ peardoc/en/package/database/db/db-common/autoexecute.xml Tue Jul 13 11:29:43 2004 @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="iso-8859-1" ?> -<!-- $Revision: 1.31 $ --> +<!-- $Revision: 1.32 $ --> <refentry id="package.database.db.db-common.autoexecute"> <refnamediv> @@ -94,8 +94,11 @@ </term> <listitem> <para> - in case of update queries, - this string will be put after the <command>WHERE</command> clause + a string to be used in the <command>WHERE</command> clause. + This is only used when <parameter>$mode</parameter> is + <constant>DB_AUTOQUERY_UPDATE</constant>. + The string is put directly into the query, so you must + escape and quote literals according to the DBMS's standards. </para> </listitem> </varlistentry> @@ -192,7 +195,7 @@ <refsect1 id="package.database.db.db-common.autoexecute.example"> &title.example; <example> - <title>Using <function>autoExecute</function></title> + <title>Using <function>autoExecute</function> in insert mode</title> <programlisting role="php"> <![CDATA[ <?php @@ -206,7 +209,30 @@ ); $res = $db->autoExecute($table_name, $fields_values, - DB_AUTOQUERY_INSERT); + DB_AUTOQUERY_INSERT); + +if (DB::isError($res)) { + die($res->getMessage()); +} +?> + ]]> + </programlisting> + </example> + + <example> + <title>Using <function>autoExecute</function> in update mode</title> + <programlisting role="php"> + <![CDATA[ +<?php +// Once you have a valid DB object named $db... +$table_name = 'user'; + +$fields_values = array( + 'country' => 'France', +); + +$res = $db->autoExecute($table_name, $fields_values, + DB_AUTOQUERY_UPDATE, "country = 'Japan'"); if (DB::isError($res)) { die($res->getMessage()); http://cvs.php.net/diff.php/peardoc/en/package/database/db/db-common/autoprepare.xml?r1=1.31&r2=1.32&ty=u Index: peardoc/en/package/database/db/db-common/autoprepare.xml diff -u peardoc/en/package/database/db/db-common/autoprepare.xml:1.31 peardoc/en/package/database/db/db-common/autoprepare.xml:1.32 --- peardoc/en/package/database/db/db-common/autoprepare.xml:1.31 Tue May 4 11:25:23 2004 +++ peardoc/en/package/database/db/db-common/autoprepare.xml Tue Jul 13 11:29:43 2004 @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="iso-8859-1" ?> -<!-- $Revision: 1.31 $ --> +<!-- $Revision: 1.32 $ --> <refentry id="package.database.db.db-common.autoprepare"> <refnamediv> @@ -89,8 +89,11 @@ </term> <listitem> <para> - in case of update queries, - this string will be put after the WHERE statement + a string to be used in the <command>WHERE</command> clause. + This is only used when <parameter>$mode</parameter> is + <constant>DB_AUTOQUERY_UPDATE</constant>. + The string is put directly into the query, so you must + escape and quote literals according to the DBMS's standards. </para> </listitem> </varlistentry> @@ -190,7 +193,34 @@ <refsect1 id="package.database.db.db-common.autoprepare.example"> &title.example; <example> - <title>Using <function>autoPrepare</function></title> + <title>Using <function>autoPrepare</function> in insert mode</title> + <programlisting role="php"> + <![CDATA[ +<?php +// Once you have a valid DB object named $db... +$table_name = 'user'; +$table_fields = array('name', 'country'); +$table_values = array('Zoe', 'France'); + +$sth = $db->autoPrepare($table_name, $table_fields, + DB_AUTOQUERY_INSERT); + +if (DB::isError($sth)) { + die($sth->getMessage()); +} + +$res =& $db->execute($sth, $table_values); + +if (DB::isError($res)) { + die($res->getMessage()); +} +?> + ]]> + </programlisting> + </example> + + <example> + <title>Using <function>autoPrepare</function> in update mode</title> <programlisting role="php"> <![CDATA[ <?php @@ -200,7 +230,7 @@ $table_values = array('Bob', 'USA'); $sth = $db->autoPrepare($table_name, $table_fields, - DB_AUTOQUERY_UPDATE, 'id = 1'); + DB_AUTOQUERY_UPDATE, "country = 'Japan'"); if (DB::isError($sth)) { die($sth->getMessage());

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