cvs: peardoc /en/package/database db.xml /en/package/database/db intro-portability.xml
| From: | Daniel Convissor | Date: | Tue, 27 Jan 2004 06:58:16 +0000 |
| Subject: | cvs: peardoc /en/package/database db.xml /en/package/database/db intro-portability.xml | ||
| Groups: | php.pear.doc | ||
| Request: | Send a blank email to pear-doc+get-2199@lists.php.net to get a copy of this message | ||
danielc Tue Jan 27 01:58:16 2004 EDT
Added files:
/peardoc/en/package/database/db intro-portability.xml
Modified files:
/peardoc/en/package/database db.xml
Log:
Add portability intro.
http://cvs.php.net/diff.php/peardoc/en/package/database/db.xml?r1=1.10&r2=1.11&ty=u
Index: peardoc/en/package/database/db.xml
diff -u peardoc/en/package/database/db.xml:1.10 peardoc/en/package/database/db.xml:1.11
--- peardoc/en/package/database/db.xml:1.10 Mon Jan 26 23:48:30 2004
+++ peardoc/en/package/database/db.xml Tue Jan 27 01:58:09 2004
@@ -1,4 +1,4 @@
-<!-- $Revision: 1.10 $ -->
+<!-- $Revision: 1.11 $ -->
<sect1 id="package.database.db">
<title>DB</title>
@@ -9,6 +9,7 @@
&package.database.db.intro-dsn;
&package.database.db.intro-connect;
+ &package.database.db.intro-portability;
&package.database.db.intro-query;
&package.database.db.intro-fetch;
&package.database.db.intro-sequences;
http://cvs.php.net/co.php/peardoc/en/package/database/db/intro-portability.xml?r=1.1&p=1
Index: peardoc/en/package/database/db/intro-portability.xml
+++ peardoc/en/package/database/db/intro-portability.xml
<!-- $Revision: 1.1 $ -->
<refentry id="package.database.db.intro-portability">
<refnamediv>
<refname>Introduction - Portability</refname>
<refpurpose>Database portability</refpurpose>
</refnamediv>
<refsect1 id="package.database.db.intro-portability.desc">
&title.desc;
<para>
Each database management system (DBMS) has it's own behaviors.
For example, some databases capitalize field names in their output,
some lowercase them, while others leave them alone. These quirks
make it difficult to port your scripts over to another server type.
PEAR DB strives to overcome these differences so your program can
switch between DBMS's without any changes.
</para>
<para>
You control which portability modes should be enabled by using
<link linkend="package.database.db.db.connect">
<function>connect</function>
</link> and
<link linkend="package.database.db.db-common.setoption">
<function>setOption</function>
</link>.
</para>
<para>
The portability modes are bitwised, so they can be combined using
<screen>|</screen> and removed using <screen>^</screen>.
See the examples section below on how to do this.
</para>
<para>
Portability mode constants and what they do:
<itemizedlist>
<listitem>
<para>
<constant>DB_PORTABILITY_NONE</constant> (default)
</para>
<para>
turn off all portability features
</para>
</listitem>
<listitem>
<para>
<constant>DB_PORTABILITY_LOWERCASE</constant>
</para>
<para>
convert names of tables and fields to lower case when using
<function>get*</function>, <function>fetch*</function> and
<function>tableInfo</function>
</para>
</listitem>
<listitem>
<para>
<constant>DB_PORTABILITY_RTRIM</constant>
</para>
<para>
right trim the data output by <function>get*</function> and
<function>fetch*</function>
</para>
</listitem>
<listitem>
<para>
<constant>DB_PORTABILITY_DELETE_COUNT</constant>
</para>
<para>
force reporting the number of rows deleted.
Some DBMS's don't count the number of rows deleted when performing
simple <screen>DELETE FROM tablename</screen> queries. This mode
tricks such DBMS's into telling the count by adding
<screen>WHERE 1=1</screen> to the end of <screen>DELETE</screen>
queries.
</para>
</listitem>
<listitem>
<para>
<constant>DB_PORTABILITY_NUMROWS</constant>
</para>
<para>
enable hack that makes <function>numRows</function> work in Oracle
</para>
</listitem>
<listitem>
<para>
<constant>DB_PORTABILITY_ALL</constant>
</para>
<para>
turn on all portability features
</para>
</listitem>
</itemizedlist>
</para>
</refsect1>
<refsect1 id="package.database.db.intro-portability.compatibility">
<title>Backwards Compatibility</title>
<para>
Some of this functionality used to be handled by the now depricated
<example>optimize</example> option. For backwards compatibility, when
this option is set to <example>portability</example>, the following
databases get these portability modes turned on:
<itemizedlist>
<listitem>
<para>
oci8:
<constant>DB_PORTABILITY_LOWERCASE</constant> and
<constant>DB_PORTABILITY_DELETE_COUNT</constant>
</para>
</listitem>
<listitem>
<para>
fbsql, mysql, mysql4, sqlite:
<constant>DB_PORTABILITY_NUMROWS</constant>
</para>
</listitem>
</itemizedlist>
</para>
<para>
When the <example>optimize</example> option gets set to
<example>performance</example> the portability mode is switched to
<constant>DB_PORTABILITY_NONE</constant>.
</para>
</refsect1>
<refsect1 id="package.database.db.intro-portability.example">
&title.example;
<example>
<title>Turn on all portability options while connecting</title>
<programlisting role="php">
<![CDATA[
<?php
require_once 'DB.php';
$dsn = 'mysql://user:password@host/database'
$options = array(
'debug' => 2,
'portability' => DB_PORTABILITY_ALL,
);
$db =& DB::connect($dsn, $options);
if (DB::isError($db)) {
die($db->getMessage());
}
?>
]]>
</programlisting>
</example>
<example>
<title>
Use <function>setOption</function> to enable portability
for lowercasing and trimming
</title>
<programlisting role="php">
<![CDATA[
<?php
// Once you have a valid DB object named $db...
$db->setOption('portability',
DB_PORTABILITY_LOWERCASE | DB_PORTABILITY_RTRIM);
?>
]]>
</programlisting>
</example>
<example>
<title>
Use <function>setOption</function> to enable all portability
options except trimming
</title>
<programlisting role="php">
<![CDATA[
<?php
// Once you have a valid DB object named $db...
$db->setOption('portability',
DB_PORTABILITY_ALL ^ DB_PORTABILITY_RTRIM);
?>
]]>
</programlisting>
</example>
</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
-->