With the function below I backup a copy of my database, but something very curious happens to me: If I do it on the local server, it responds:
INSERT INTO calendar (guest) VALUES (" muà ± oz Gómez ");
On the remote server:
INSERT INTO calendar (guest) VALUES (" muñoz Gómez ");
same structure BD, same version php 7.0, ????
I DO NOT UNDERSTAND !!!
Thanks
function backupDatabaseTables($dbHost,$dbUsername,$dbPassword,$dbName,$tables = '*'){
//connect & select the database
$db = new mysqli($dbHost, $dbUsername, $dbPassword, $dbName);
//get all of the tables
if($tables == '*'){
$tables = array();
$result = $db->query("SHOW TABLES");
while($row = $result->fetch_row()){
$tables[] = $row[0];
}
}else{
$tables = is_array($tables)?$tables:explode(',',$tables);
}
//loop through the tables
foreach($tables as $table){
$result = $db->query("SELECT * FROM $table");
$numColumns = $result->field_count;
$return .= "DROP TABLE IF EXISTS $table;";
$campos2=mysqli_query($db, "SELECT COLUMN_NAME as columna FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name = '$table' and table_schema = 'trinid_alquiler' " );
$a=0;
while ($campos= mysqli_fetch_assoc($campos2)){
if ($a < ($numColumns-1))
{$retur.=$campos['columna'].",";}else{$retur.=$campos['columna'];}
$a++;
}
$result2 = $db->query("SHOW CREATE TABLE $table");
$row2 = $result2->fetch_row();
$return .= "\n\n".$row2[1].";\n\n";
for($i = 0; $i < $numColumns; $i++){
while($row = $result->fetch_row()){
$return .= "INSERT INTO $table";
$return .= "(".$retur.")";
$return.=" VALUES(";
for($j=0; $j < $numColumns; $j++){
//$row[$j] = addslashes($row[$j]);
if (isset($row[$j]) and ($row[$j]!=="")){ $return .= '"'.$row[$j].'"' ; }
else if(is_null($row[$j] )) { $return .= 'NULL'; }
else { $return .= '""'; }
if ($j < ($numColumns-1)) { $return.= ','; }
}
$return .= ");\n";
}$retur="";
}
$return .= "\n\n\n";
}