/** * Get full database structure * * @param string $dsn Datasource name * @param bool $count Count each table entries * * @return mixed * @throws Exception */ static function getDatabaseStructure($dsn, $count = false) { $databases = CImportTools::getAllDatabaseInfo(); if (!isset($databases[$dsn])) { throw new Exception("DSN not found : {$dsn}"); } $db_info = $databases[$dsn]; $ds = CSQLDataSource::get($dsn); // Description file $description = new DOMDocument(); $description->load($db_info["description_file"]); $description->_xpath = new DOMXPath($description); $db_info["description"] = $description; // Tables $table_names = $ds->loadTables(); $tables = array(); foreach ($table_names as $_table_name) { $_table_info = CImportTools::getTableInfo($ds, $_table_name); if ($count) { $_table_info["count"] = $ds->loadResult("SELECT COUNT(*) FROM {$_table_name}"); } $tables[$_table_name] = $_table_info; } $db_info["tables"] = $tables; return $db_info; }