0

I need help regarding migrating my OCI upload file to postgresql file. I've tried multiple ways from Youtube. I am new to pgsql and really in a pinch right now. Need help. Thank you!.

Here is the code:

$file = basename($_SERVER['PHP_SELF']); //get index.php
if ($file!='index.php') include_once "nologin.php";
   
   
$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'];
    
    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);
}
Roberto Hernandez
  • 8,231
  • 3
  • 14
  • 43
Syahmie
  • 9
  • 1
  • what is the error ? – Roberto Hernandez Sep 02 '21 at 06:47
  • Theres not an error.It just doesn't work.I need to migrate the codes to postgresql and having a big problem. it will work on Oracle of course. Just need to replace it with postgreSQL.I've spent hours trying to find the solution but cant seem to find it – Syahmie Sep 02 '21 at 06:55
  • Take a look at [Migrate your mindset too](https://blog.sql-workbench.eu/post/migrate-your-mindset/). While its examples are from MS SQL Server the lesson is the same ***You need to understand what the old code does in order to rewrite to the new system***. You cannot expect to just dump code from one database to another. Particular here as OCL is Oracle proprietary software (Oracle Call Interface). There is NO direct replacement in Postgres. – Belayer Sep 02 '21 at 23:05
  • What is your question? You should read You Should read https://stackoverflow.com/help/how-to-ask to ask good question – mshomali Sep 05 '21 at 09:00
  • Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. – Community Sep 05 '21 at 09:00

0 Answers0