RE: [PEAR] Re: DB Sequences

From: Date: Wed, 17 Jul 2002 17:55:20 +0000
Subject: RE: [PEAR] Re: DB Sequences
References: 1  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-1919@lists.php.net to get a copy of this message
El mié, 17-07-2002 a las 19:12, LIMBOURG Arnaud escribió: > We agree on that, that is the power of sequences. > > But what about the approach of having a row in a "sequence" table and not in > a table ? > Sorry I don't catch the point. Let me explain how the sequence emulation for MySQL works. We have one table with only one value on it. The schema for that table is: CREATE TABLE ${seqname} ( id INTEGER UNSIGNED AUTO_INCREMENT NOT NULL, PRIMARY KEY(id) ) Each time you call the $db->nextID() method, you are really updating the previous value plus one, and returning it (atomically for avoiding concurrency problems). You can create that table according to this schema by hand (for the CREATE priviledges problem) or just do a: $ phpcli -r "include 'DB.php'; DB::connect('mysql://..')->createSequence('foo');"; Well that code only works with ZE2 :-) (if I didn't understand wrong the new features). Let's say: $ phpcli -r "include 'DB.php'; $db = DB::connect('mysql://..'); $db->createSequence('foo');"; Note that this emulates how sequences works. I don't see the need of having a table with fileds "sequence name -> value" when you can just have that "sequence" table with one value, usable by all your tables. Please re-elaborate your question if you mean other thing :-) Tomas V.V.Cox

« previous php.pear.general (#1919) next »