Hi All,

There have been a few occasions where I've wanted a quick and easy way
to access a single database table as part of an SCA component
implementation.  I'm just adding the finishing touches (at least to
the point where it might do something useful) to a binding called
simpledb.  This gives you a CRUD (create, retrieve, update and delete)
service interface over a database table.  It's a bit Active Record
like, but more simplistic.  Here's how it is used...

The code below shows how to do CRUD against a table called 'contact'.

<?php
require 'SCA/SCA.php';

$dbservice = SCA::getService('contact', 'simpledb',
                             array('config' => 'config/
mysql_config.ini'));

$contact = $dbservice->createDataObject('http://example.org',
'contact');
$contact->shortname = 'bertie';
$contact->fullname = 'Bertie Example';
$contact->email = '[EMAIL PROTECTED]';
$id = $dbservice->create($contact);
echo "Created: $id";

$contact = $dbservice->retrieve('bertie');
echo "Retrieved: " . $contact->fullname;

$contact->fullname = 'Bertie B Example';
$dbservice->update($contact->shortname, $contact);

$dbservice->delete($contact->shortname);

?>

The ini file can contain the following:

dsn = "mysql:host=localhost;dbname=email"
namespace = "http://example.org";
username =xxx
password = xxx
use_lower_case = 1

All but the dsn are optional.  The namespace becomes the namespace of
any SDOs created for the table.  The use_lower_case value lets you
configure how the SDO property names will appear (The property names
are derived directly from the live database so don't have to be
specified).  If set to false, then what the database uses will be used
for the SDO properties (e.g. DB2 will be uppercase).

An SCA reference example would look something like:

    /**
     * The database service
     *
     * @reference
     * @binding.simpledb contact
     *
     * @config mysql_config.ini
     */
    public $dbservice;

I'd be interested in any feedback, thoughts on how this might be
extended, and so on.  My hope is this could be used to simplify
creating Web services backed by a database (it is a better fit than
the SDO relational DAS).  I think we could also add optimistic
concurrency quite easily, but using an identifier tag generated by the
binding, rather than SDO change summaries.

If folks are happy with this, then I'll check it into DUNLIN once I've
got the main capabilities up and running.

Regards,  Graham


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"phpsoa" group.
To post to this group, send email to phpsoa@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.co.uk/group/phpsoa?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to