Create SQLITE or .SQL Dump generate

<?php
//attach the source database file to the bulkload connection object;
include "config.php";

$getappid = $_GET['id'];
$getappname = $_GET['appname'];

@$deletefolder = unlink('../images/App_images/'.$getappname.'/'.$getappname.'.sqlite');
@$deletezip = unlink('../images/App_images/'.$getappname.'/'.$getappname.'.zip');
@$sqldeletezip = unlink('../images/App_images/'.$getappname.'/'.$getappname.'.sql');

$newdb = new SQLite3('../images/App_images/'.$getappname.'/'.$getappname.'.sqlite');
$newdb->exec('CREATE TABLE appInfo(id INTEGER PRIMARY KEY, appname VARCHAR NOT NULL, title VARCHAR NOT NULL, category VARCHAR NOT NULL, description LONGTEXT NOT NULL, image VARCHAR NOT NULL, links VARCHAR NOT NULL)');

$newdir = 'sqlite:../images/App_images/'.$getappname.'/'.$getappname.'.sqlite';
$newdbh  = new PDO($newdir) or die("cannot open the database");

    $sqlnewdir = '../images/App_images/'.$getappname.'/'.$getappname.'.sql';
    $dbhost =   "localhost";
    $dbuser =   "root";
    $dbpass =   "";
    $dbname =   "";
   
    exec("mysqldump --user=$dbuser --password='$dbpass' --host=$dbhost $dbname >".$sqlnewdir."");

    $myfile = fopen($sqlnewdir, "w") or die("Unable to open file!");
    $createTable = ("CREATE TABLE IF NOT EXISTS appInfo(id INTEGER PRIMARY KEY AUTOINCREMENT, appname VARCHAR NOT NULL, title VARCHAR NOT NULL, category VARCHAR NOT NULL, description LONGTEXT NOT NULL, image VARCHAR NOT NULL, links VARCHAR NOT NULL);");
    fwrite($myfile,$createTable);

$data= array();
    $sth = $dbh->prepare("SELECT dis.*,myapp.appname,category.category
FROM app_description as dis
INNER JOIN category
    on dis.categoryid = category.id
INNER JOIN myapp
    on dis.appid = myapp.id
WHERE dis.appid='$getappid'");
    $sth->execute();
    $result = $sth->fetchAll(PDO::FETCH_ASSOC);
   
    foreach($result as $row){   
       
     $description=$row['description'];
     $image=$row['image'];
     $appname=$row['appname'];
     $category=$row['category'];
     $title=$row['title'];
     $links=$row['links'];
   
     $query =  ("INSERT INTO `appInfo`(`appname`, `title`, `category`, `description`, `image`, `links`) VALUES ('$appname','$title','$category','$description','$image','$links')");
     $result = $newdbh->query($query);
     $writeToFile = "INSERT INTO appInfo(appname, title, category, description, image, links) VALUES('$appname','$title','$category','$description','$image','$links');". PHP_EOL;
     fwrite($myfile,$writeToFile);
    }

   // *************** include "zipmaker.php";**************


    $rootPath = realpath('../images/App_images/'.$getappname);
    // Initialize archive object
    $zip = new ZipArchive();
    $zip->open('../images/App_images/'.$getappname.'/'.$getappname.'.zip', ZipArchive::CREATE | ZipArchive::OVERWRITE);
   
// Create recursive directory iterator
/** @var SplFileInfo[] $files */
$files = new RecursiveIteratorIterator(
    new RecursiveDirectoryIterator($rootPath),
    RecursiveIteratorIterator::LEAVES_ONLY
);

foreach ($files as $name => $file)
{
    // Skip directories (they would be added automatically)
    if (!$file->isDir())
    {
        // Get real and relative path for current file
        $filePath = $file->getRealPath();
        $relativePath = substr($filePath, strlen($rootPath) + 1);

        // Add current file to archive
        $zip->addFile($filePath, $relativePath);
    }
}

// Zip archive will be created only after closing object
$zip->close();

echo '../images/App_images/'.$getappname.'/'.$getappname.'.zip';

?>
Previous
Next Post »