Inserting date into oracle database from PHP

后端 未结 2 1480
无人共我
无人共我 2021-01-22 17:47

I have a question regarding inserting date from PHP into Oracle DB

so i have this in my PHP,

$delivDate = strval($_POST[\'deliveryDate\']);

echo $delivD         


        
相关标签:
2条回答
  • 2021-01-22 18:20

    Few days back I face the same issue and it was date format issue. So I change the date format and it works for me. You can try below code and test it and if it works than modify code as per your need.

    $delivDate = date('d-m-Y h:i:s', strtotime($_POST['deliveryDate']));    
    INSERT INTO DELIVERY (DELIVERY_DATE) VALUES (to_date('".$delivDate."','dd-mm-yy hh24:mi:ss'))";
    
    0 讨论(0)
  • 2021-01-22 18:31

    I'm guessing its a date format issue but you need to have an oci_error statement to expose any sql related errors.

    Please refer to the oci_execute section here http://php.net/manual/en/function.oci-execute.php. There are a few examples where oci_execute is used in if statements implying that its a boolean return. If its false, fork into the oci_error code and expose your sql issues.

    Excerpted from link above to save you time:

    <?php 
    $q = oci_parse($c, ""); 
    if($q != false){ 
        // parsing empty query != false 
        if(oci_execute($q){ 
            // executing empty query != false 
            if(oci_fetch_all($q, $data, 0, -1, OCI_FETCHSTATEMENT_BY_ROW) == false){ 
                // but fetching executed empty query results in error (ORA-24338: statement handle not executed) 
                $e = oci_error($q); 
                echo $e['message']; 
            } 
        } 
        else{ 
            $e = oci_error($q); 
            echo $e['message']; 
        } 
    } 
    else{ 
        $e = oci_error($link); 
        echo $e['message']; 
    } 
    ?>
    
    0 讨论(0)
提交回复
热议问题