cvs: peardoc /en/package/database mdb2.xml /en/package/database/mdb2 intro-quote.xml

From: Date: Mon, 27 Nov 2006 21:28:49 +0000
Subject: cvs: peardoc /en/package/database mdb2.xml /en/package/database/mdb2 intro-quote.xml
Groups: php.pear.doc 
Request: Send a blank email to pear-doc+get-8932@lists.php.net to get a copy of this message
quipo Mon Nov 27 21:28:49 2006 UTC Added files: /peardoc/en/package/database/mdb2 intro-quote.xml Modified files: /peardoc/en/package/database mdb2.xml Log: added a "Quoting and escaping" page. Please revise it. http://cvs.php.net/viewvc.cgi/peardoc/en/package/database/mdb2.xml?r1=1.11&r2=1.12&diff_format=u Index: peardoc/en/package/database/mdb2.xml diff -u peardoc/en/package/database/mdb2.xml:1.11 peardoc/en/package/database/mdb2.xml:1.12 --- peardoc/en/package/database/mdb2.xml:1.11 Tue Nov 21 12:19:45 2006 +++ peardoc/en/package/database/mdb2.xml Mon Nov 27 21:28:49 2006 @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="ISO-8859-1" ?> -<!-- $Revision: 1.11 $ --> +<!-- $Revision: 1.12 $ --> <sect1 id="package.database.mdb2"> <title>MDB2</title> <para> @@ -10,6 +10,7 @@ &package.database.mdb2.intro-connect; &package.database.mdb2.intro-query; &package.database.mdb2.intro-fetch; + &package.database.mdb2.intro-quote; &package.database.mdb2.intro-execute; &package.database.mdb2.intro-transaction; &package.database.mdb2.intro-module; http://cvs.php.net/viewvc.cgi/peardoc/en/package/database/mdb2/intro-quote.xml?view=markup&rev=1.1 Index: peardoc/en/package/database/mdb2/intro-quote.xml +++ peardoc/en/package/database/mdb2/intro-quote.xml <?xml version="1.0" encoding="iso-8859-1" ?> <!-- $Revision: 1.1 $ --> <refentry id="package.database.mdb2.intro-quote"> <refnamediv> <refname>Quoting and escaping</refname> <refpurpose>Quote values in a suitable format to compose a query.</refpurpose> </refnamediv> <refsect1 id="package.database.mdb2.intro-quote.desc"> &title.desc; <para> <classname>MDB2</classname> provides a <function>quote</function> method to quote a value into a DBMS specific format that is suitable to compose query statements. It has four parameters (only the first one is required): the value to be quoted, its <ulink url="http://cvs.php.net/viewcvs.cgi/*checkout*/pear/MDB2/docs/datatypes.html">datatype</ulink>, wether or not to quote the value, and wether or not to escape the wildcards in the value. If you don't provide the datatype, it will be guessed from the value. </para> <example> <title>Doing a query with quoted values</title> <programlisting role="php"> <![CDATA[ <?php // Create a valid MDB2 object named $mdb2 // at the beginning of your program... require_once 'MDB2.php'; $mdb2 =& MDB2::connect('pgsql://usr:pw@localhost/dbnam'); if (PEAR::isError($mdb2)) { die($mdb2->getMessage()); } // some sample values to be inserted $id = 1; $name = 'sample item'; $time = date('Y-m-d H:i:s'); // Proceed with a query... $query = 'INSERT INTO tablename (id, itemname, saved_time) VALUES (' . $mdb2->quote($id, 'integer') .', ' . $mdb2->quote($name, 'text') .', ' . $mdb2->quote($time, 'timestamp') .')'; $res =& $mdb2->query($query); ?> ]]> </programlisting> </example> <para> If you use <link linkend="package.database.mdb2.intro-execute">prepared statements</link>, then quoting will be done automatically, you don't need to do it yourself. </para> </refsect1> <refsect1 id="package.database.mdb2.intro-quote.quote-identifiers"> <title>Identifiers</title> <para> You can quote the db identifiers (table and field names) with <function>quoteIdentifier</function>. The delimiting style depends on which database driver is being used. <emphasis>NOTE:</emphasis> just because you CAN use delimited identifiers, it doesn't mean you SHOULD use them. In general, they end up causing way more problems than they solve. Anyway, it may be necessary when you have a reserved word as a field name (in this case, we suggest you to change it, if you can). </para> </refsect1> <refsect1 id="package.database.mdb2.intro-quote.escape"> <title>Escape</title> <para> If you want to escape a value, without surrounding it with quotes, you can use the <function>escape</function> method. If you also want to escape the wildcards (_ and %), set the second parameter to &true; </para> <para> If you just want to escape the wildcards in a value, you can use the <function>escapePattern</function> method. </para> </refsect1> </refentry> <!-- Keep this comment at the end of the file Local variables: mode: sgml sgml-omittag:t sgml-shorttag:t sgml-minimize-attributes:nil sgml-always-quote-attributes:t sgml-indent-step:1 sgml-indent-data:t sgml-parent-document:nil sgml-default-dtd-file:"../../../../manual.ced" sgml-exposed-tags:nil sgml-local-catalogs:nil sgml-local-ecat-files:nil End: vim600: syn=xml fen fdm=syntax fdl=2 si vim: et tw=78 syn=sgml vi: ts=1 sw=1 -->

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