Fork me on GitHub

adodb - auto_inc val  Bottom

  • hi,
    what's the best way to get the auto_inc value of a table? is there a function bult into adodb or is it just a matter of querying the info_schema (which the db_user "may not" have read access to)

    this works fine, but i'm concerned about DB permissions:

    Code

    $sql = "SELECT AUTO_INCREMENT
                FROM information_schema.TABLES
                WHERE TABLE_SCHEMA='"
    .$GLOBALS['pnconfig']['dbname']."'
                AND TABLE_NAME='"
    .$ptable."'";
        $result =& $dbconn->execute($sql);
        list($next_post_id) = $result->fields;


    thanks for any insight/suggestions.
  • this seems to work well too:

    Code

    $sql = "SHOW TABLE STATUS WHERE Name='table_name'";
    $result =& $dbconn->execute($sql);
    $table_status = $result->GetRowAssoc(false);
    $next_post_id = $table_status['auto_increment'];


    PS: this might be better suited in the DB forum.. sorry.



    edited by: InvalidResponse, Apr 09, 2007 - 03:13 AM
  • *GenID* should do the job - one shouldn't rely on the existence of autoincrement anyway...

    --
    regards from germany
    ..::[Zikula Application Framework]::.. ..::[SEO-Blog]::.. ..::[CMS Sicherheit]::..
  • hi andreas,
    GenID returns zero .. can you explain why you shouldn't rely on the existence of an autoincrement value? I'm assuming you mean the GenID function is unreliable and shouldn't be relied on.. which is true.

    thanks



    edited by: InvalidResponse, Apr 09, 2007 - 01:34 PM

This list is based on users active over the last 60 minutes.