[horde] Horde 4 with oci8

Luis Felipe Marzagao/Andamentos lfbm.andamentos at gmail.com
Thu Apr 21 00:45:44 UTC 2011

Em 20/04/11 01:24, Chuck Hagenbuch escreveu:
> Quoting Luis Felipe Marzagao/Andamentos <lfbm.andamentos at gmail.com>:
>> By the way, has the horde project ever considered using Doctrine 
>> (http://www.doctrine-project.org/)?
>> I'm doing some tests and it seems to integrate and work pretty nice. 
>> That way wrinting code just once would already provide support for 
>> the most important dbases (oracle, mysql, postgre, microsoft sql 
>> server etc.).
>> In case it has already been considered, why wasn't it incorporated?
> It was discussed at least a little. Personally, it didn't fit with how 
> I wanted Horde_Db to work. And I really don't like the XML-heavy 
> configuration that was used, at least the last time I looked at it.
> I didn't undertake fleshing out Horde_Db lightly, but I think it's 
> been a worthwhile library already.
> -chuck
Nice to know it has been analysed.

I started toying with Doctrine 1.2.3. Let me share my experience with it 
so far.

At least for me there was absolutely no XML configuration at all.

Installed Doctrine via pear:

pear install pear.doctrine-project.org/Doctrine-1.2.3.tgz

Then, you only need to set a db schema once, and it can be yaml format, 
like this:

   tableName: cashier_clients
     client_id as id: { type: string(32), primary: true }
     client_owner as owner: { type: string(255), notnull: true }
     client_name as name: { type: string(255), notnull: true }
     client_is_human as is_human: { type: boolean, notnull: true }
     client_tax_number as tax_number: { type: string(14), notnull: false }
     Searchable: { fields: [name, tax_number] }
     Transactions: { class: Cashier_Transactions, local: id, foreign: 
client_id, type: many }
     Aliases: { class: Cashier_Aliases, local: id, foreign: client_id, 
type: many, cascade: [delete] }

The yaml file can be automatically created from an already existing db 
table or manually edited.
(... Doctrine_Core::generateYamlFromDb('Models/Yaml/schema.yml') ... );

(The searchable attribute automatically takes care of creating db 
columns for an indexing system in order to increase search performance, 
really handy!)

Then, this will generate the php classes (only needed once):

     CASHIER_BASE . '/lib/Models/Schema/cashier_schema.yml',
     CASHIER_BASE . '/lib/Models')

To begin using it, bootstrap the doctrine core:

require_once 'Doctrine.php';
spl_autoload_register(array('Doctrine', 'autoload'));
Doctrine_Core::loadModels(CASHIER_BASE . '/lib/Models');

Then, set up a connection:

$dsn = 'mysql:dbname=testdb;host=';
$user = 'dbuser';
$password = 'dbpass';
$dbh = new PDO($dsn, $user, $password);
$conn = Doctrine_Manager::connection($dbh);

Then, use it, for example:

$id = 1;
$q = Doctrine_Query::create($conn)
            ->select('c.*, a.name')
            ->from('Cashier_Clients c')
            ->leftJoin('c.Aliases a')
            ->addWhere('c.id = ?', $id)

$result = $q->fetchOne();

Or, for example:

$clientTable = Doctrine_Core::getTable('Cashier_Clients');
$client = $clientTable->find('155b128a5d264564103464a773d780a9');
$client['name'] = 'John Doe';

And so on...

And the code will always be the above, no matter what db backend you 
have (mysql, oracle etc.). You only change the connection parameters 
according to your db backend.

Also, documentation from the project is really good.

I'm not an advanced progammer and I know this is no big news, but it 
seems pretty tight and easy for me. And is well documented and ready for 
major db backends.

Anyway, I managed to integrate it pretty nicely with Horde 3.

Just wanted to share the experience.

Luis Felipe

More information about the horde mailing list