From 4ca9f8be5e7cdf364b07bed3c29c413d82c2478b Mon Sep 17 00:00:00 2001 From: Victor Westerlund Date: Mon, 16 Feb 2026 11:27:30 +0100 Subject: [PATCH] feat: add method for querying the current `AUTO_INCREMENT` for a table (#5) This will be used to retrieve the primary key for newly inserted rows. Reviewed-on: https://codeberg.org/vlw/wp/pulls/5 --- src/Database.php | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/Database.php b/src/Database.php index 2e9a007..7a224c1 100644 --- a/src/Database.php +++ b/src/Database.php @@ -76,6 +76,19 @@ parent::__construct(); } + /** + * Return the current AUTO_INCREMENT value for a given table + * + * @param string $table + * @return int + */ + public function latest(string $table): int { + return $this->execute_query("SELECT AUTO_INCREMENT FROM information_schema.TABLES WHERE TABLE_SCHEMA = ? AND TABLE_NAME = ?", [ + self::$name, + self::get_table($table) + ])->fetch_assoc()["AUTO_INCREMENT"]; + } + /** * Fetch and set the WordPress siteurl from the options table *