public static function fromTable($tableName)
    {
        $repos = Repository::getDefaultRepositoryClassName();

        // Get the create table syntax for the table - we'll analyse this and build our schema accordingly.
        $row = $repos::returnFirstRow(
            "SHOW CREATE TABLE $tableName"
        );

        $sql = $row["Create Table"];

        $lines = explode("\n", $sql);

        // First and last lines aren't needed
        $lines = array_slice($lines, 1, -1);

        $comparisonSchema = new MySqlComparisonSchema();

        foreach ($lines as $line) {
            $line = trim($line);

            // If the line starts with a back tick we have a column
            if ($line[0] == "`") {
                $default = null;

                preg_match("/`([^`]+)`/", rtrim($line, ','), $matches);

                $name = $matches[1];

                $comparisonSchema->columns[$name] = rtrim(trim($line), ",");
            } else {
                $words = explode(" ", $line);

                $indexKeywords = ["PRIMARY", "KEY", "UNIQUE", "FULLTEXT"];

                if (in_array($words[0], $indexKeywords)) {
                    $index = preg_replace('/\s+/', ' ', rtrim(trim($line), ","));
                    $index = preg_replace('/^UNIQUE KEY/', 'UNIQUE', $index);
                    $comparisonSchema->indexes[] = $index;
                }
            }
        }

        return $comparisonSchema;
    }
public static function fromTable($tableName)
    {
        $repos = Repository::getDefaultRepositoryClassName();

        // Get the create table syntax for the table - we'll analyse this and build our schema accordingly.
        $row = $repos::returnFirstRow(
            "SHOW CREATE TABLE $tableName"
        );

        $sql = $row["Create Table"];

        $lines = explode("\n", $sql);

        // First and last lines aren't needed
        $lines = array_slice($lines, 1, -1);

        $comparisonSchema = new MySqlComparisonSchema();

        foreach ($lines as $line) {
            $line = trim($line);

            // If the line starts with a back tick we have a column
            if ($line[0] == "`") {
                $default = null;

                preg_match("/`([^`]+)`/", rtrim($line, ','), $matches);

                $name = $matches[1];

                $comparisonSchema->columns[$name] = rtrim(trim($line), ",");
            } else {
                $words = explode(" ", $line);

                $indexKeywords = ["PRIMARY", "KEY", "UNIQUE", "FULLTEXT"];

                if (in_array($words[0], $indexKeywords)) {
                    $index = preg_replace('/\s+/', ' ', rtrim(trim($line), ","));
                    $index = preg_replace('/^UNIQUE KEY/', 'UNIQUE', $index);
                    $comparisonSchema->indexes[] = $index;
                }
            }
        }

        return $comparisonSchema;
    }
public static function fromTable ( $ tableName ) { $ repos = Repository :: getDefaultRepositoryClassName ( ) ; // Get the create table syntax for the table - we'll analyse this and build our schema accordingly. $ row = $ repos :: returnFirstRow ( "SHOW CREATE TABLE $tableName" ) ; $ sql = $ row [ "Create Table" ] ; $ lines = explode ( "\n" , $ sql ) ; // First and last lines aren't needed $ lines = array_slice ( $ lines , 1 , - 1 ) ; $ comparisonSchema = new MySqlComparisonSchema ( ) ; foreach ( $ lines as $ line ) { $ line = trim ( $ line ) ; // If the line starts with a back tick we have a column if ( $ line [ 0 ] == "`" ) { $ default = null ; preg_match ( "/`([^`]+)`/" , rtrim ( $ line , ',' ) , $ matches ) ; $ name = $ matches [ 1 ] ; $ comparisonSchema -> columns [ $ name ] = rtrim ( trim ( $ line ) , "," ) ; } else { $ words = explode ( " " , $ line ) ; $ indexKeywords = [ "PRIMARY" , "KEY" , "UNIQUE" , "FULLTEXT" ] ; if ( in_array ( $ words [ 0 ] , $ indexKeywords ) ) { $ index = preg_replace ( '/\s+/' , ' ' , rtrim ( trim ( $ line ) , "," ) ) ; $ index = preg_replace ( '/^UNIQUE KEY/' , 'UNIQUE' , $ index ) ; $ comparisonSchema -> indexes [ ] = $ index ; } } } return $ comparisonSchema ; }
Returns a MySqlComparisonSchema reflecting the schema of a database table.

@param  $tableName
@return MySqlComparisonSchema
Returns a MySqlComparisonSchema reflecting the schema of a database table .