Search

I'm using the importcsv extension to port over a bunch of store information into my database. I'm also using the address location field (well, fields) extension to get my google maps information. The problem is, the address location field needs an entry_id from the sym_entries table. Since i've been adding and deleting entries, the entry_id column isn't always going to be sequential so I can't just grab the "last" entry and increment the column number.

I've been trying stuff like this:

        SELECT AUTO_INCREMENT
        FROM information_schema.tables as T1
        WHERE `T1`.table_name = `sym_entries`
        AND `T1`.table_schema = `db_name_from_config`;

but I keep on getting an error like this:

Unknown column 'sym_entries' in 'where clause' in query: SELECT SQL_CACHE AUTO_INCREMENT
        FROM information_schema.tables
        WHERE table_name = `sym_entries`
        AND table_schema = db_name_from_config; on line 823 of /site/v2/stores/symphony/lib/toolkit/class.mysql.php

I don't know mysql very well at all, but my guess is that accessing the information_schema requires root/admin access (correct me if i'm wrong) so would think this isn't a reliable query for this stuff.

does anyone know of any reliable way to get the next auto increment value from a table?

bah...per usual, after more digging and trying to figure out the ever so cryptic mysql errors, this is what i did:

    $entries = Symphony::Database()->fetch("SHOW TABLE STATUS LIKE 'sym_entries'");
    $nextAutoInc = null;
    foreach($entries as $row) {
        foreach($row as $field => $value) {
            if ($field == 'Auto_increment') {
                Symphony::Log()->writeToLog($field . ' = ' . $value);
                $nextAutoInc = $value;
            }
        }
    }

The dumb error i was stuck on was with the LIKE condition - i didn't have my table name wrapped in single quotes (didn't try with double) and mysql was just giving me You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'sym_entries' at line 1 with me not realizing the actual necessity for the quotes until after I looked at the docs.

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details