Your IP : 216.73.216.136


Current Path : /var/www/html/dhandapaniimports/
Upload File :
Current File : /var/www/html/dhandapaniimports/receiptheaderfull.php

<?php

$tns2 = "(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 111.92.43.75)(PORT = 1521)) (CONNECT_DATA = (SID = XE)))";
if ($conn = oci_connect("PDJ","PDJ", $tns2))
{
echo "Connected to DataBase";
}
else
{
echo ("could not connect to DataBase");
exit;
}
$localconn = new mysqli("localhost","root","Ktp@201*","dhandapani");

// Check connection
if ($localconn->connect_errno) {
    echo "Failed to connect to MySQL: " . $localconn->connect_error;
    exit();
  }

//$s = oci_parse($conn, "SELECT * FROM CHITRECEIPTHEADER where TRUNC (CRHXDATE) = TRUNC (SYSDATE)");
$s = oci_parse($conn, "SELECT * FROM CHITRECEIPTHEADER");
oci_execute($s);
echo "<pre>";

while ($row = oci_fetch_assoc($s)) {
    $rows[] = $row;  
    $keys=array_keys($row);
	$values = array_values($row);
	$key_placeholders = implode(',',$keys);
    $values_placeholders = "'" . implode ( "', '", $values ) . "'";
    $alreadyexist = "select * from chitreceipt_header_temp where CRHXID='".$row['CRHXID']."'";
    $alreadyresult = mysqli_query($localconn,$alreadyexist);
    $alreadyexistrow = mysqli_fetch_row($alreadyresult);
    if(!empty($alreadyexistrow)){
        $updaterow = '';
        $i=0;
        end($row);
        $lastkey = key($row);
        
        foreach($row as $key=>$value){
            $updaterow .= "'".$key."' = '".$value."'";
            if($lastkey != $key){
                $updaterow .= ",";
            }
            $i++;
        }
        $query = "UPDATE chitreceipt_header_temp SET $updaterow WHERE CRHXID = '".$row['CRHXID']."'";
    }else{
        $query = "INSERT INTO chitreceipt_header_temp (".$key_placeholders.") VALUES (".$values_placeholders.")";
    }
     $result = mysqli_query($localconn,$query);
     $installmentsql = "select * from chitmember_installmentdetail where CMIDCMXXID='".$row['CRHXCMXXID']."' and CMIDCRHXID ='".$row['CRHXID']."'";
    
     $installmentresult = mysqli_query($localconn,$installmentsql);
     $installmentrow = mysqli_fetch_assoc($installmentresult);
    
        if(empty($installmentrow)){
            $ociinstallmentsql = "select * FROM CHITMEMBERINSTALLMENTDETAIL where CMIDCMXXID='".$row['CRHXCMXXID']."' and CMIDCRHXID ='".$row['CRHXID']."'";
            $inslmentociresult = oci_parse($conn, $ociinstallmentsql);
            oci_execute($inslmentociresult);
            $installmentocirow = oci_fetch_assoc($inslmentociresult);
            if(!empty($installmentocirow)){
            $keys=array_keys($installmentocirow);
            $values = array_values($installmentocirow);
            $key_placeholders = implode(',',$keys);
            $values_placeholders = "'" . implode ( "', '", $values ) . "'";
                $updaterow = '';
                $i=0;
                end($installmentocirow);
                $lastkey = key($installmentocirow);
                
                foreach($installmentocirow as $key=>$value){
                    $updaterow .= "`".$key."` = '".$value."'";
                    if($lastkey != $key){
                        $updaterow .= ",";
                    }
                    $i++;
                }
            $installmentquery = "UPDATE chitmember_installmentdetail SET $updaterow  WHERE CMIDID = '".$installmentocirow['CMIDID']."'";
            $installmentresult = mysqli_query($localconn,$installmentquery);
           }
        }
}
echo "Imported Successfully";exit();