We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 50573
    • 4 Posts
    I have this:
    $query = "SELECT `AUTO_INCREMENT` FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'my_db_name' AND TABLE_NAME = 'my_table_name'";
    $result = $modx->query($query);
    if ( !is_object($result) )
    {
    // report Error
    print "Error in case get\n";
    }
    else
    {
    $row = $result->fetch(PDO::FETCH_ASSOC);
    $id = $row['AUTO_INCREMENT'];
    print "id = ".$id."\n";
    }

    I get this:
    id =

    So, the query seems to have returned an object, but there is no data in the row for AUTO_INCREMENT?
    Is there a better way to do this?

    Thanks in advance.

    P

    This question has been answered by phay3s. See the first response.

      • 3749
      • 24,544 Posts
      You might find this useful: http://bobsguides.com/blog.html/2014/11/19/using-my-sql-in-modx/

      As I understand it, the SELECT for your query needs to be a table name. I could be wrong.

      SELECT table_name FROM INFORMATION_SCHEMA.TABLES
        WHERE table_schema = 'db_name'



      What is it you're trying to do?
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
      • discuss.answer
        • 50573
        • 4 Posts
        Thanks for the response.
        The form of the select is actually correct (though I cannot take credit for that; I got it from another post).
        I found the problem. Where I put in the table name, I had the capitalization wrong.
        In phpMyAdmin 'table_xxx' worked, but when going through modx it needed to be 'table_XXX'.

        Again, thanks for responding.
        And for anyone else reading, the format of the sql actually works, but check your names more carefully than I did!

        P