public static function handleException(Exception $exception) { if (Core::$cli) { Core::cliMessage($exception->getMessage(), 'red'); Core::cliMessage($exception->getLine() . ' in file ' . $exception->getFile(), 'red'); } }
public function query($sql, $data = array()) { $statement = $this->pdo->prepare($sql); if (!$statement->execute($data)) { Core::showMessage('SQL-Fehler: ' . $sql, 'red'); Core::showMessage('SQL-String: ' . print_r($statement, 1)); Core::showMessage(' >> ' . $statement->errorInfo()[2], 'red', 1); $this->pdo->rollBack(); return false; } return $statement; }
/** * @param Database $database * * @return array */ private function getTableStructur($database) { $tables = $database->query('SHOW TABLE STATUS')->fetchAll(); $returnTables = array(); foreach ($tables as &$table) { $newTable = array(); $newTable['name'] = $table['Name']; $newTable['engine'] = $table['Engine']; $newTable['collation'] = $table['Collation']; Core::showMessage(' > Table "' . $newTable['name'] . '"', 'white', 1, false); $newTable['fields'] = $this->getColumnStructur($database, $newTable['name']); Core::showMessage(' done ', 'green', 1); array_push($returnTables, $newTable); } return $returnTables; }
private function connectDatabases($sourceName, $targetName) { // Connection to the Source-Database $sourceDB = new Database(); $sourceConfig = $this->storageDatabases[$sourceName]; $sourceDB->connect($sourceConfig['engine'], $sourceConfig['host'], $sourceConfig['name'], $sourceConfig['user'], $sourceConfig['password']); $this->sourceDB = $sourceDB; Core::showMessage(" > SourceDB connected", 'green'); // Connection to the Target-Database $targetDB = new Database(); $targetConfig = $this->storageDatabases[$targetName]; $targetDB->connect($targetConfig['engine'], $targetConfig['host'], $targetConfig['name'], $targetConfig['user'], $targetConfig['password']); $this->targetDB = $targetDB; Core::showMessage(" > TargetDB connected", 'green'); if ($this->sourceDB->pdo !== false and $this->targetDB->pdo !== false) { return true; } return false; }