PHP How to change upload file from OCI(oracle) to PG(postgresql)

Hello,I need help changing the coding from OCI(oracle) to PG(postgresql)…
here is the coding.

    <?php
    $file = basename($_SERVER['PHP_SELF']); //get index.php
    if ($file!='index.php') include_once "nologin.php";
    /*
       // Edit upload location here
       $destination_path = getcwd().DIRECTORY_SEPARATOR;

       $result = 0;
       
       $target_path = $destination_path . basename( $_FILES['myfile']['name']);
       
       $type = $_FILES['myfile']['type'];
    	
       if(@move_uploaded_file($_FILES['myfile']['tmp_name'], $target_path)) {
          $result = 1;
       }
       
       sleep(1);
    */
       
       
    $result = 0;
    if(isset($_POST['submitBtn']) && $_FILES['myfile']['size'] > 0)
    {
    	$fileName = $_FILES['myfile']['name'];
    	$tmpName  = $_FILES['myfile']['tmp_name'];
    	$fileSize = $_FILES['myfile']['size'];
    	$fileType = $_FILES['myfile']['type'];
    	$no_kp_baru   = $_POST['no_kp_baru'];
    	$latihan_id = $_POST['latihan_id'];
    	$tkh_mula1 = $_POST['tkh_mula'];
    	$masa_mula = $_POST['masa_mula'];
    	//$fp      = fopen($tmpName, 'r');
    	//$content = fread($fp, filesize($tmpName));
    	//$content = addslashes($content);
    	//fclose($fp);
    	
    	list($d, $m, $y) = explode('/', $tkh_mula1);//'dd/mm/yyyy' format
    	$mk=mktime(0, 0, 0, $m, $d, $y);
    	$tkh_mula=strftime('%d-%b-%Y',$mk);

    	if(!get_magic_quotes_gpc())
    	{
    		$fileName = addslashes($fileName);
    	}

    	include_once "../db_conn.php";
    	
    	$sql = "
    	update log_latihan set
    		PENGESAHAN = NULL,
    		TKH_PENGESAHAN = NULL,
    		ID_PENGESAH = NULL
    	where
    		NO_KP_BARU = :NO_KP_BARU
    		and LATIHAN_ID = :LATIHAN_ID
    		and TKH_MULA = :TKH_MULA
    		and MASA_MULA = :MASA_MULA
    		";
    	
    	// Update using bind variables
    	$parse = oci_parse($conn, $sql);
    	oci_bind_by_name($parse, ":NO_KP_BARU", $no_kp_baru);
    	oci_bind_by_name($parse, ":LATIHAN_ID", $latihan_id);
    	oci_bind_by_name($parse, ":TKH_MULA", $tkh_mula);
    	oci_bind_by_name($parse, ":MASA_MULA", $masa_mula);
    	oci_execute($parse);
    	//echo oci_num_rows($parse);
    	if (oci_num_rows($parse))
    	{
    	
    		$stmt = oci_parse($conn, "INSERT INTO log_latihan_sijil (no_kp_baru,latihan_id,tkh_mula,masa_mula,nama_fail,type,saiz_fail,tkh_upload,sijil) 
    		VALUES(:NO_KP_BARU,:LATIHAN_ID,to_date(:TKH_MULA,'DD/MM/YYYY'),:MASA_MULA,:NAMA_FAIL,:TYPE,:SAIZ_FAIL,sysdate,EMPTY_BLOB()) RETURNING sijil INTO :FILE_CONTENT");
    		
    		$lob = oci_new_descriptor($conn, OCI_D_LOB);
    		oci_bind_by_name($stmt, ':FILE_CONTENT', $lob, -1, OCI_B_BLOB);
    		oci_bind_by_name($stmt, ":NO_KP_BARU", $no_kp_baru);
    		oci_bind_by_name($stmt, ":LATIHAN_ID", $latihan_id);
    		oci_bind_by_name($stmt, ":TKH_MULA", $tkh_mula1);
    		oci_bind_by_name($stmt, ":MASA_MULA", $masa_mula);
    		oci_bind_by_name($stmt, ":NAMA_FAIL", $fileName);
    		oci_bind_by_name($stmt, ":TYPE", $fileType);
    		oci_bind_by_name($stmt, ":SAIZ_FAIL", $fileSize);
    		oci_execute($stmt, OCI_DEFAULT);
    		//var_dump(oci_error($stmt));

    		if ($lob->savefile($tmpName)) {
    			oci_commit($conn);
    			$result=1;
    		}
    		$lob->free();
    		oci_free_statement($stmt);
    	}
    	oci_free_statement($parse);
    }
    sleep(1);
    ?>
    <script language="javascript" type="text/javascript">window.top.window.stopUpload(<?php echo $result; ?>);</script>

I recommend using the PDO extension - PHP: PDO - Manual Once you do this, the php statements will remain the same for different database types. The only issue then is any difference in the sql syntax between the different database types.

Sponsor our Newsletter | Privacy Policy | Terms of Service