SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    It's been real... Forbes's Avatar
    Join Date
    Dec 2004
    Location
    Yorkshire, England
    Posts
    676
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Pear nextId() questions

    Hi all!

    I'm working on some additions to my transactions class, which essentially deals with all database requests across my application.

    Anyway, I'm using Pear DB and I'm in need to 'knowing' the ID of the current asset / record.

    Now, the way that Pear works is different to how MySQL handles this. Where MySQL let's you know the ID of the recently created record, Pear favours giving you the next auto-increment ID of the record.

    You access this with the DB_common::nextId() method, which I've just added.

    But there's a problem.

    Rather than this ID being the actual auto-increment ID for the table, the number instead starts at 1 and increments onwards from thereon in.

    Not very helpful as you can imagine.

    Anyone know either a fix for this or a better way of doing this?

    I'm sure to be eternally grateful for any help. You will be handsomely rewarded in the next life, I'm sure...

  2. #2
    SitePoint Wizard
    Join Date
    Aug 2004
    Location
    California
    Posts
    1,672
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It sounds like you may be using a seperate sequence table. Check to see if there is a table with a "_seq" ending on the name.
    Christopher

  3. #3
    It's been real... Forbes's Avatar
    Join Date
    Dec 2004
    Location
    Yorkshire, England
    Posts
    676
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by arborint
    It sounds like you may be using a seperate sequence table. Check to see if there is a table with a "_seq" ending on the name.
    Hi Chris!

    No. There aren't any tables with a suffix like that.

    I'm the only one who has access to any of this stuff...

  4. #4
    It's been real... Forbes's Avatar
    Join Date
    Dec 2004
    Location
    Yorkshire, England
    Posts
    676
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    In the Pear documentation, there's an example:
    PHP Code:
    <?php
    // Once you have a valid DB object named $db...
    $id $db->nextId('mySequence');
    if (
    PEAR::isError($id)) {
    die(
    $id->getMessage());
    }

    // Use the ID in your INSERT query
    $res =& $db->query("INSERT INTO myTable (id, text) VALUES ($id, 'foo')");
    ?>
    But there's no mention of where from or how mySequence is created.

    Even when following up the Sequences documentation, which is a little odd.

    That's one of more disappointing aspects of the Pear website. A lot of the documentation is either incomplete or assumes a huge amount while offering no real means of discovering the very things they're taking for granted that you -- the reader -- are meant to know beforehand...

  5. #5
    SitePoint Wizard
    Join Date
    Aug 2004
    Location
    California
    Posts
    1,672
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, if you are sick of PEAR try something else. I would recommend somethink like lastcraft's MysqlConnection class instead. You can find it http://www.sitepoint.com/forums/showthread.php?t=214183 as part of the Changes library. Simpler yet more powerful.
    Christopher

  6. #6
    It's been real... Forbes's Avatar
    Join Date
    Dec 2004
    Location
    Yorkshire, England
    Posts
    676
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm not sick of Pear at all, I'd just like better documentation.

    Besides, I'm not in a position to go and change my mind. I've made Pear a sizable part of what I'm working on...


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •