I am currently working on an script that will easily import an backup in 2 clicks, but i can’t find any information on how to import and .gz file.
and .sql file works great but if im going to decompress it i can just aswell just import it using phpmyadmin.
when i currently try to import the .gz file i just get one massive error of unreadable characters.
How can i make it so i can import an .gz file
The point here is that it is an WEB based importer
$userName = "root";
$password = "";
$dbName = "test";
$conn = @new mysqli($serverName,$userName,$password,$dbName);
if ($conn->connect_errno) {
echo "Failed to connect to MySQL: " . $con->connect_errno;
echo "<br/>Error: " . $con->connect_error;}
$fileName = "189_dump.sql.gz";
$temp = "";
$lines = file($fileName);
foreach($lines as $line){
if(substr($line, 0, 2) == '--' || $line == '')
continue;
$temp .= $line;
if(substr(trim($line), -1, 1) == ';'){
$conn->query($temp) or print('Error performing query '<strong>' . $temp . '': '. '<br /><br />');
$temp = "";
}
}
echo "imported db (or not)";
?>
2
Answers
This is how i fixed it:
$lines = gzfile($fileName);
If you have system() allowed you can: