Setting Up DB DataObject

From Web Developer Network Wiki
Jump to: navigation, search
  • On the ucommxsrv1 filesystem, create a file like the following (OUTSIDE OF THE WEB ROOT):
[DB_DataObject]
database    = mysql://mysqluser:password@localhost/databasename
schema_location = /Library/WebServer/Documents/directory/DataObjects
class_location  = /Library/WebServer/Documents/directory/DataObjects
require_prefix  = DataObjects/
class_prefix    = DataObjects_

(save this as databasename_DB_DataObject.ini) Be sure to enter the correct username, password, database, and webserver directory. Now we run a php script to create the php class files on the server.

  • Execute the following command:

/usr/local/php/bin/php /usr/local/php/lib/php/DB/DataObject/createTables.php databasename_DB_DataObject.ini

This will create a file for each table in the database which will be used to access that table in an object-oriented fashion.

Now create a file in the web directory containing the same configuration options: /Library/WebServer/Documents/directory/config.inc.php:

<?php
require_once('DB/DataObject.php');
require_once('DB/DataObject/FormBuilder.php');
require_once('DB/DataObject/FormBuilder/QuickForm/SubForm.php');
$options = &PEAR::getStaticProperty('DB_DataObject','options');
$options = array(
    'database'         => 'mysql://mysqluser:password@localhost/databasename',
    'schema_location'  => '/Library/WebServer/Documents/directory/DataObjects',
    'class_location'   => '/Library/WebServer/Documents/directory/DataObjects',
    'require_prefix'   => 'DataObjects/',
    'class_prefix'     => 'DataObjects_',
);
Personal tools
Namespaces

Variants
Actions
Navigation
Toolbox