intoducing dbobj

From: Date: Sat, 28 Jan 2006 19:41:07 +0000
Subject: intoducing dbobj
Groups: php.pecl.dev 
Request: Send a blank email to pecl-dev+get-3457@lists.php.net to get a copy of this message
Hi, First i want to show you what I've been doing in the last months. I'm developing a php extension (that someday may became part of PECL). I call it dbobj, and is a high-performance object/relational persistence layer. As for now, it works only with postgreSQL, but I plan support for other DBMSs. Let's see a simple example how it works: <?php ini_set('dbobj.connStr','user=netigdev password=*** host=localhost'); ini_set('dbobj.case_sensitive',true); class autoIDtest extends dbobj { static $dbobj_config = array('table'=>'autoIDtestTable',
       'dbProps'=>array(
            //these are fields in the table
           'id'=>array('dbField'=>'id','type'=>'S','PK'=>true),   //type S means Serial/Sequence
           't'=>array('dbField'=>'textField','type'=>'T'),   //type T = Text
       ),
       'objProps'=>array(
            //these fields will be accessible from PHP code
           'id'=>array('sources'=>array('id'),'type'=>'i','access'=>'pub'),
           't'=>array('sources'=>'t','type'=>'S','access'=>'pub'),
       )
); } $idtest = new autoIDtest(); //no PKs given, so this will be a new object (we can give PKs, then it'll load a record) var_dump($idtest->id); $idtest->t = "id: {$idtest->id}"; ?> Two sql queries are executed during this script: 1: SELECT nextval('"autoIDtestTable_id_seq'");
      executed by $idtest = new autoIDtest();
2: INSERT INTO "autoIDtestTable"("id","alma")VALUES($1,$2);
      executed by the destructor of $idtest
nice, isn't it? Second, comes why i'm really writing to this list. This whole thing worths nothing if it isn't capable of handling connections between tables. Internally this will be done by defining an objProp of type relation. My problem is that i don't now what format in the dbobj_config to use. I'm thinking of something like this:
               'parent'=>array('sources'=>'parent','type'=>'>relatedClass','access'=>'pub')
This means that parent is FK in the current table and the only PK field of relatedClass will be connected to it. This will cause an error if relatedClass doesn't have exactly one PK.
I'd be glad to see any ideas for this problem, or suggestions for dbobj! Thanks for reading my longer-than-it-should-be post, however I hope I was clear, if not, please ask! Adam Bankó

« previous php.pecl.dev (#3457) next »