From 873c1d592b00cc8d22ca9e589b1fc7c2567acf18 Mon Sep 17 00:00:00 2001 From: Victor Westerlund Date: Mon, 16 Feb 2026 11:15:17 +0100 Subject: [PATCH] feat: add method for querying the current AUTO_INCREMENT for a table --- 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 *