Introduction - Portability

Introduction - Portability -- Database portability features

Description

Each database management system (DBMS) has its 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.

You control which portability modes are enabled by using the portability configuration option. Configuration options are set via connect() and setOption().

The portability modes are bitwised, so they can be combined using | and removed using ^. See the examples section below on how to do this.

Portability Mode Constants

Backwards Compatibility

Some of this functionality used to be handled by the now deprecated optimize option. For backwards compatibility, when this option is set to portability, the following databases get these portability modes turned on:

When the optimize option gets set to performance the portability mode is switched to DB_PORTABILITY_NONE.

Example

Example 39-1. Turning on all portability options while connecting


<?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 (PEAR::isError($db)) {
    die($db->getMessage());
}
?>

Example 39-2. Using setOption() to enable portability for lowercasing and trimming


<?php
// Once you have a valid DB object named $db...
$db->setOption('portability',
        DB_PORTABILITY_LOWERCASE DB_PORTABILITY_RTRIM);
?>

Example 39-3. Using setOption() to enable all portability options except trimming


<?php
// Once you have a valid DB object named $db...
$db->setOption('portability',
        DB_PORTABILITY_ALL DB_PORTABILITY_RTRIM);
?>