Re: problems with nextId
| From: | Markus Wolff | Date: | Fri, 16 Aug 2002 17:56:08 +0000 |
| Subject: | Re: problems with nextId | ||
| References: | 1 2 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-2140@lists.php.net to get a copy of this message | ||
On Fri, 16 Aug 2002 12:10:13 -0500
"Matt McDonald" <matt@coffeecup.com> wrote:
> Thanks for the help, I think I'm starting to get somewhere, but I'm still
> not fully understanding where the problem is. FYI, I'm using MySQL 3.23.39
> I gave the account full database permissions, then tried your script listed
> below, and came back with this:
>
> An error has occured: DB Error: DB backend not capable
>
> So is it my version of MySQL the problem (it's fairly close to the latest
> stable version available), or is it the way I have my tables configured?
It´s highly unlikely that MySQL is the problem here. It seems you have a
_very_ old version of PEAR::DB - check http://pear.php.net/ for
the
latest version.
> I'm still kind of confused how sequences work. Right now, I've got 22
> tables set up in by database. So when I call nextId to set up a new
> sequence, does it scan all tables and come up with a value that would work
> no matter what table I insert into? If that is the case, perhaps there is a
> table I have configured that stumps the scanning process?
No tables are scanned. It´s really not that complicated. If you call
$newId = $db->nextId("mySequence");
...PEAR::DB looks if a Sequence called "mySequence" exists. If yes, it
will get a new value from the sequence. If the sequence doesn´t exist,
PEAR::DB will try to create a new one called "mySequence", which will
start with the value 1.
So, if you always fetch your IDs for a Table from the same sequence,
you´ll always have unique IDs. It´s pretty much the same as having an
auto_increment value in your table, but the same sequence can also be
used by multiple tables.
As MySQL doesn´t support sequences natively, PEAR::DB emulates them by
creating a table for each new sequence that has only one column, which
is an auto_increment value. Anytime you call nextId(), PEAR::DB will
insert a new value in the table and return the ID that was generated.
Other databases, like PostgreSQL or Oracle, handle sequences natively,
so no emulation is needed there.
Regards,
Markus
--
Markus Wolff <wolff@21st.de>