Installation and Usage Example

Installation and Usage Example – Installation and example for the usage of MDB2_Schema

Installation

First you need MDB2 installed:

$ pear install --alldeps MDB2

You should install a driver for each database you are working with. For MySQL it would be:

$ pear install MDB2_Driver_Mysql

For some hints refers to MDB2 documentation or try in a UNIX-like system:

$ pear remote-list | grep MDB2

MDB2_Schema is a separate package, and can also be installed using the PEAR installer:

$ pear install --alldeps MDB2_Schema-beta

now you should be ready :)

Usage Example

To create an instance of the MDB2_Schema class you can use the factory(), which accepts a $dsn or an array. The factory method also accepts an existing MDB2 object. In the example below, we will just use a $dsn.

<?php
require_once 'MDB2/Schema.php';

$options = array(
    
'log_line_break' => '<br>',
    
'idxname_format' => '%s',
    
'debug' => true,
    
'quote_identifier' => true,
    
'force_defaults' => false,
    
'portability' => false
);
$dsn 'mysql://root:@localhost/MDB2Example';

$schema =& MDB2_Schema::factory($dsn$options);

if (
PEAR::isError($schema)) {
    
$error $schema->getMessage();
}

if (isset(
$error)) {
    
var_dump($error);
}

$schema->disconnect();
?>
Introduction to MDB2_Schema (Previous) Generating the definition array of a physical database or MDB2 XML (Next)
Last updated: Wed, 26 Nov 2014 — Download Documentation
Do you think that something on this page is wrong? Please file a bug report or add a note.
View this page in:

User Notes:

There are no user contributed notes for this page.