Estoy intentando hacer la comparación de dos bbdd. Lo que hago primero es sacar la estructura la primera bbdd en local de esta forma:
Código PHP:
session_start();
$seleccion = $_POST['db'];
$_SESSION['seleccion'] = $seleccion;
$link = mysql_connect("localhost","root","") or die (mysql_error());
$sql = "SELECT schema_name FROM information_schema.schemata WHERE schema_name = '$seleccion'";
$res = mysql_query($sql, $link) or die (mysql_error());
$fila = mysql_fetch_array($res);
$sql2 = "SELECT table_name FROM information_schema.tables WHERE table_schema = '".$fila['schema_name']."'";
$res2 = mysql_query($sql2, $link) or die (mysql_error());
$i=0;
$c=0;
while($fila2 = mysql_fetch_array($res2)){
$array1[$c]=$fila2[0];
$sql5 = "SELECT column_name, column_type FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name = '".$fila2['table_name']."' AND table_schema = '".$fila['schema_name']."'";
$res5 = mysql_query($sql5,$link) or die (mysql_error());
$_SESSION['columnas'][$i] = "create table <strong>".$fila2['table_name']."</strong> (";
while($fila5 = mysql_fetch_array($res5)){
$_SESSION['columnas'][$i] = $_SESSION['columnas'][$i]." ".$fila5['column_name']." ".$fila5['column_type'].",";
}
$_SESSION['columnas'][$i] = substr($_SESSION['columnas'][$i], 0, -1);
$_SESSION['columnas'][$i] = $_SESSION['columnas'][$i].");";
$i++;
$c++;
}
$_SESSION['cuantos'] = $i;
Código PHP:
$copiar = $_POST['copiar'];
$_SESSION['copiar'] = $copiar;
$link2 = mysql_connect("servidor","usuario","******")or die(mysql_error());
$sql3 = "SELECT schema_name FROM information_schema.schemata WHERE schema_name LIKE '%$copiar%'";
$res3 = mysql_query($sql3, $link2) or die (mysql_error());
$j=0;
while ($fila3 = mysql_fetch_array($res3)) {
$_SESSION['columnas2'][$j] = '<strong>'.$fila3['schema_name'].'</strong><br>';
$sql4 = "SELECT table_name FROM information_schema.tables WHERE table_schema = '".$fila3['schema_name']."'";
$res4 = mysql_query($sql4, $link2) or die (mysql_error());
$c=0;
while($fila4 = mysql_fetch_array($res4)){
$array2[$c]=$fila4[0];
$sql6 = "SELECT column_name, column_type FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name = '".$fila4['table_name']."' AND table_schema = '".$fila3['schema_name']."'";
$res6 = mysql_query($sql6,$link) or die (mysql_error());
$_SESSION['columnas2'][$j] = $_SESSION['columnas2'][$j]."create table <strong>".$fila4['table_name']."</strong> (";
while($fila6 = mysql_fetch_array($res6)){
$_SESSION['columnas2'][$j] = $_SESSION['columnas2'][$j]." ".$fila6['column_name']." ".$fila6['column_type'].",";
}
$_SESSION['columnas2'][$j] = substr($_SESSION['columnas2'][$j], 0, -1);
$_SESSION['columnas2'][$j] = $_SESSION['columnas2'][$j].");<br>";
$j++;
$c++;
}
$_SESSION['cuantos2'] = $j;
}
Gracias de antemano. Saludos