L
LabConker
Beta
Verificado por Whatsapp
¡Usuario con pocos negocios! ¡Utiliza siempre saldo de Forobeta!
Para los que hagan análisis de tablas en mysql les dejo una buena herramienta para que puedan consultar los CREATE de las tablas que quieran.
DEBEN CREAR ESTAS DOS TABLAS
CREATE TABLE
CREATE TABLE
EN LA TABLA cmp_table_catalog ponen el nombre de la tabla que quieren buscar ( pongan todas las que quieran).
luego ejecutan este php
<?php
// PON TUS CREDENCIALES AQUÍ
$host = 'localhost';
$dbname = 'database';
$user = 'root';
$pass = '';
try {
// Crear conexión PDO
$pdo = new PDO("mysql:host=$host;dbname=$dbname;charset=utf8mb4", $user, $pass, [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
]);
// Obtener las tablas habilitadas
$stmt = $pdo->prepare("SELECT table_name FROM cmp_table_catalog WHERE is_enabled = 'enabled'");
$stmt->execute();
$tables = $stmt->fetchAll(PDO::FETCH_COLUMN);
if (empty($tables)) {
throw new Exception("No hay tablas habilitadas en cmp_table_catalog.");
}
// Concatenar el SHOW CREATE TABLE de cada tabla
$fullSql = "";
foreach ($tables as $table) {
$stmt2 = $pdo->query("SHOW CREATE TABLE
$row = $stmt2->fetch(PDO::FETCH_ASSOC);
if (!$row || !isset($row['Create Table'])) {
throw new Exception("No se pudo obtener SHOW CREATE TABLE para la tabla $table");
}
$fullSql .= $row['Create Table'] . ";\n\n";
}
// Guardar el SQL en archivo tablas_sistema.txt
$filename = DIR . DIRECTORY_SEPARATOR . 'tablas_sistema.txt';
if (file_put_contents($filename, $fullSql) === false) {
throw new Exception("Error al guardar el archivo $filename");
}
echo "Archivo '$filename' creado con éxito.\n";
} catch (Exception $e) {
echo "Error: " . $e->getMessage() . "\n";
}
recibirán un archivo tablas_sistema.txt
DEBEN CREAR ESTAS DOS TABLAS
CREATE TABLE
cmp_table_catalog
( id
int(10) unsigned NOT NULL AUTO_INCREMENT, table_name
varchar(255) NOT NULL COMMENT 'Nombre de la tabla a analizar', is_enabled
enum('enabled','disabled') NOT NULL DEFAULT 'enabled' COMMENT 'Estado de la tabla: enabled o disabled', created_at
timestamp NOT NULL DEFAULT current_timestamp() COMMENT 'Fecha de creación', updated_at
timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp() COMMENT 'Última actualización', PRIMARY KEY (id
)) ENGINE=InnoDB AUTO_INCREMENT=22 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Catálogo de tablas habilitadas para análisis de componentes'CREATE TABLE
cmp_table_definitions_log
( id
int(10) unsigned NOT NULL AUTO_INCREMENT, generated_sql
longtext NOT NULL COMMENT 'Script SQL generado con las definiciones de tablas', created_at
timestamp NOT NULL DEFAULT current_timestamp() COMMENT 'Fecha de generación del script', PRIMARY KEY (id
)) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='Registro de scripts SQL generados a partir de las tablas habilitadas'EN LA TABLA cmp_table_catalog ponen el nombre de la tabla que quieren buscar ( pongan todas las que quieran).
luego ejecutan este php
<?php
// PON TUS CREDENCIALES AQUÍ
$host = 'localhost';
$dbname = 'database';
$user = 'root';
$pass = '';
try {
// Crear conexión PDO
$pdo = new PDO("mysql:host=$host;dbname=$dbname;charset=utf8mb4", $user, $pass, [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
]);
// Obtener las tablas habilitadas
$stmt = $pdo->prepare("SELECT table_name FROM cmp_table_catalog WHERE is_enabled = 'enabled'");
$stmt->execute();
$tables = $stmt->fetchAll(PDO::FETCH_COLUMN);
if (empty($tables)) {
throw new Exception("No hay tablas habilitadas en cmp_table_catalog.");
}
// Concatenar el SHOW CREATE TABLE de cada tabla
$fullSql = "";
foreach ($tables as $table) {
$stmt2 = $pdo->query("SHOW CREATE TABLE
$table
");$row = $stmt2->fetch(PDO::FETCH_ASSOC);
if (!$row || !isset($row['Create Table'])) {
throw new Exception("No se pudo obtener SHOW CREATE TABLE para la tabla $table");
}
$fullSql .= $row['Create Table'] . ";\n\n";
}
// Guardar el SQL en archivo tablas_sistema.txt
$filename = DIR . DIRECTORY_SEPARATOR . 'tablas_sistema.txt';
if (file_put_contents($filename, $fullSql) === false) {
throw new Exception("Error al guardar el archivo $filename");
}
echo "Archivo '$filename' creado con éxito.\n";
} catch (Exception $e) {
echo "Error: " . $e->getMessage() . "\n";
}
recibirán un archivo tablas_sistema.txt