<?php
	$connect = mysqli_connect("localhost","root","","design_datas");
	$today = date('Y-m-d');
	$session_user = 'cron';

	function convertToReadableSize($size){
	  $base = log($size) / log(1024);
	  $suffix = array("", "KB", "MB", "GB", "TB");
	  $f_base = floor($base);
	  return round(pow(1024, $base - floor($base)), 1) . $suffix[$f_base];
	}

	/*$check_bk = mysqli_query($connect,"select * from backup_details where ((start_date LIKE '%".$today."%') or (end_date LIKE '%".$today."%')) and status='1' and backup_type='1'");
	$check_rows = mysqli_num_rows($check_bk);*/

	$backupFile = 'database1_backup_'.date("YmdHis").'.sql';
	$export = exec('D:\xampp\mysql\bin\mysqldump -u root design_datas  -r "C:\Users\iniya\Downloads\database1_backup_'.date("YmdHis").'.sql.zip"', $output, $return);
	$fsize = '';//convertToReadableSize(filesize('C:\Users\iniya\Downloads\\'.$backupFile));

	if(!$return){
		$qurty = mysqli_query($connect,"INSERT INTO `backup_details`(`id`, `start_date`, `end_date`, `status`,`file_name`,`file_size`, `created_by`,`backup_type`) VALUES (NULL, now(), now(), '1','".$backupFile."','".$fsize."','".$session_user."','1')");
	} else {
		$qurty = mysqli_query($connect,"INSERT INTO `backup_details`(`id`, `start_date`, `end_date`, `status`,`file_name`,`file_size`, `created_by`,`backup_type`) VALUES (NULL, now(), now(), '0','".$backupFile."','".$fsize."','".$session_user."','1')");
	}

?>