Skip to content

Instantly share code, notes, and snippets.

@jonathandavis
Last active December 17, 2015 05:08
Show Gist options
  • Save jonathandavis/5555308 to your computer and use it in GitHub Desktop.
Save jonathandavis/5555308 to your computer and use it in GitHub Desktop.
<?php
/**
* Provides the installed database schema version from the database (if available)
*
* Queries the database to get the installed database version number. If not available,
* also checks the legacy
*
* @author Jonathan Davis
* @since 1.3
*
* @param string $legacy Set to anything but boolean false to attempt to lookup the version from the pre-1.2 settings table
* @return integer The installed database schema version number (0 means not installed)
**/
public static function dbversion ( $legacy = false ) {
$source = $legacy ? 'setting' : self::$table;
$table = DatabaseObject::tablename($source);
$version = DB::query("SELECT value FROM $table WHERE name='db_version'", 'col');
// Try again using the legacy table
if ( false === $version && false === $legacy ) $version = self::dbversion('legacy');
return (int)$version;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment