/** * Checks the currently existing table against the provided SQL schema in its associated file * * @param string $table The name of the table to check */ private function checkTable($table) { // Get the fields from the existing table $fields = DatabaseManager::instance()->Table($table)->fetchAll(PDO::FETCH_COLUMN); // Get the table schema from the table structure in the file $schema = $this->grabTableInfo($table)[0]; // Get the fields/columns from the schema - these will be used for comparison $columns = $schema->Columns(); // Get the keys from the schema - used to determine if the key needs to be added $keys = $schema->Keys(); $toAdd = []; // Compare the current table fields to the files fields for ($i = 0; $i < count($columns); $i++) { $add = true; // Get the current column name $colname = $columns[$i]['name']; // Check to see if the column name from the schema exists in the current table schema for ($j = 0; $j < count($fields); $j++) { // If the column does exist, skip it if ($colname == $fields[$j]) { $add = false; break; } } // If the column does not exist, add it to the list of columns that need to be re-added if ($add) { $toAdd[count($toAdd)] = $columns[$i]; } } // If there are any columns to be added, add them. // This check might be redundant as technically it should not get here unless there are columns missing. if (count($toAdd) > 0) { $this->alterTable($table, $toAdd, $keys); } }
public static function getInstance() { if (self::$instance == null) { $className = __CLASS__; self::$instance = new $className(); } return self::$instance; }
private static function getInstance() { if (!self::$instance) { // If no instance then make one self::$instance = new self(); } return self::$instance->dbConnection; }
/** * Reset the internal static instance * * @return void */ public static function resetInstance() { if (!self::$instance) { return; } self::$instance->reset(); self::$instance = null; }