Hi Everyone,
Kindly help me replicate the queries in qlik view the same wriiten in php code..any leads.Thanks
<?php
require_once 'config.php';
try {
$inputFile = $inputFolder."/data_integrity_inputfile.csv";
$currentTime = date("Y_m_d_H_i_s");
if(is_dir($outputFolder) == false)
{
mkdir($outputFolder);
}
$outputCsv = fopen($outputFolder."/data_integrity_outputfile_".$currentTime.".csv","w");
$file = fopen($inputFile,"r");
$rowFlag = false;
$headers = [];
$result = [];
$sourceConditionDate = '';
$destinationConditionDays = '';
$sourceResult = 0;
$destinationResult = 0;
while(! feof($file))
{
$fileRows = fgetcsv($file);
if(!$rowFlag){
fputcsv($outputCsv,$fileRows);
$rowFlag = true;
continue;
}
$daysToCheck = $fileRows[1];
$sourceDbName = $fileRows[2];
$sourceTableName = $fileRows[3];
$sourceTableColomn = $fileRows[4];
$sourceConditionColumn = $fileRows[5];
$queryMethod = $fileRows[6];
$destinationDbName = $fileRows[7];
$destinationTableName = $fileRows[8];
$destinationTableColomn = $fileRows[9];
$destinationConditionColumn = $fileRows[10];
$connectionSourceDb = connectDb($sourceDbName);
$connectionDestinationDb = connectDb($destinationDbName);
if($sourceConditionColumn == 'created_at' || $sourceConditionColumn == 'updated_at'){
$sourceConditionDays = date("Y-m-d", strtotime("- $daysToCheck day"));
}
if($destinationConditionColumn == 'created_at' || $destinationConditionColumn == 'updated_at'){
$destinationConditionDays = date("Y-m-d", strtotime("- $daysToCheck day"));
}
if($fileRows){
if($connectionSourceDb){
$sourceSql = "SELECT $queryMethod($sourceTableColomn) as $queryMethod FROM $sourceTableName WHERE $sourceConditionColumn <= $sourceConditionDays";
$sourceResult = $connectionSourceDb->query($sourceSql);
if($sourceResult){
$sourceData=$sourceResult->fetch_assoc();
$sourceResult = $sourceData[$queryMethod];
$fileRows[11] = $sourceResult;
}
}
if($connectionDestinationDb){
$destinationSql = "SELECT $queryMethod($destinationTableColomn) as $queryMethod FROM $destinationTableName WHERE $destinationConditionColumn <= $destinationConditionDays";
$destinationResult = $connectionDestinationDb->query($destinationSql);
if($destinationResult){
$destinationData = $destinationResult->fetch_assoc();
$destinationResult = $destinationData[$queryMethod];
$fileRows[12] = $destinationResult;
}
}
}
if(is_array($fileRows)){
$difference = $sourceResult - $destinationResult;
$fileRows[13] = $difference;
fputcsv($outputCsv, $fileRows);
}
}
fclose($outputCsv);
fclose($file);
echo "Integrity check completed";
} catch (Exception $e) {
echo $e->getMessage();
}