par
djtec » 07 nov. 2013, 20:25
Voilà j'ai modifié
<?php
$file = "db1.sql";
$db1 = file_get_contents($file);
$file_content = explode(";", $db1);
$tables = array();
function trimUltime($chaine){
$chaine = trim($chaine);
$chaine = str_replace("\t", " ", $chaine);
$chaine = eregi_replace("[ ]+", " ", $chaine);
return $chaine;
}
foreach($file_content as $k => $table) {
$table = trim($table);
$table = str_replace("\n", "", $table);
$table = trimUltime($table);
if(empty($table)) {
continue;
}
preg_match("/^CREATE TABLE (.*?) (\() (.*?)(\)\))/i", $table, $matches);
$table_name = str_replace("`", "", $matches[1]);
$tables[$table_name] = array(
'fields' => array(),
'primary_key' => null,
'key' => null,
'engine' => null
);
foreach(explode(', ', $matches[3]) as $key => $value) {
if(strstr($value, 'PRIMARY KEY')) {
$value = str_replace("PRIMARY KEY (`", "", $value);
$value = str_replace("`", "", $value);
$tables[$table_name]['primary_key'][] = $value;
} elseif(strstr($value, 'KEY')) {
$value = str_replace("KEY", "", $value);
$value = explode(" ", $value);
$value = trim($value[1], "`");
$tables[$table_name]['key'][] = $value;
} else {
$tables[$table_name]['fields'][] = $value;
}
}
}
echo '<pre>';
var_dump($tables);
echo '</pre>';
Et là c'est bon j'ai plus que à faire quelles modifications et surtout pouvoir modifier les 2 tableaux pour voir ce qui est différent et là c'est pas gagner
Voilà j'ai modifié
[php]<?php
$file = "db1.sql";
$db1 = file_get_contents($file);
$file_content = explode(";", $db1);
$tables = array();
function trimUltime($chaine){
$chaine = trim($chaine);
$chaine = str_replace("\t", " ", $chaine);
$chaine = eregi_replace("[ ]+", " ", $chaine);
return $chaine;
}
foreach($file_content as $k => $table) {
$table = trim($table);
$table = str_replace("\n", "", $table);
$table = trimUltime($table);
if(empty($table)) {
continue;
}
preg_match("/^CREATE TABLE (.*?) (\() (.*?)(\)\))/i", $table, $matches);
$table_name = str_replace("`", "", $matches[1]);
$tables[$table_name] = array(
'fields' => array(),
'primary_key' => null,
'key' => null,
'engine' => null
);
foreach(explode(', ', $matches[3]) as $key => $value) {
if(strstr($value, 'PRIMARY KEY')) {
$value = str_replace("PRIMARY KEY (`", "", $value);
$value = str_replace("`", "", $value);
$tables[$table_name]['primary_key'][] = $value;
} elseif(strstr($value, 'KEY')) {
$value = str_replace("KEY", "", $value);
$value = explode(" ", $value);
$value = trim($value[1], "`");
$tables[$table_name]['key'][] = $value;
} else {
$tables[$table_name]['fields'][] = $value;
}
}
}
echo '<pre>';
var_dump($tables);
echo '</pre>';[/php]
Et là c'est bon j'ai plus que à faire quelles modifications et surtout pouvoir modifier les 2 tableaux pour voir ce qui est différent et là c'est pas gagner