Get next auto increment value from entries table?
This is an open discussion with 1 reply, filed under Troubleshooting.
Search
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.
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, theentry_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:
but I keep on getting an error like this:
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?