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
This commit is contained in:
Victor Westerlund 2026-02-16 11:27:30 +01:00
parent 28f31250fa
commit fa4147e7ab

View file

@ -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
*