简体   繁体   中英

Warning: oci_execute(): ORA-01821: date format not recognized

I am new to Oracle database. I have created a table in Oracle. I can get some value from HTML using PHP using $_POST[] , and connection works fine.

Now I want to store current Date from PHP into an Oracle table as Date type. But I don't know the correct way to bind the Date, and I get this error:

在此处输入图片说明

Here is the code:

$year = $_POST["SALYR"];
$month = $_POST["SALMT"];
$empID = $_POST["EMPID"];
$dptCode = $_POST["DPTID"];
$salHD = 'A9';
$description = $_POST["DESCR"];
$amount = $_POST["ALAMT"];
$optID = 111;
$trDate = date("Y/m/d", strtotime( date("Y/m/d") ) );  

    $query = "INSERT INTO PAYROLLFILE VALUES (:bind1, :bind2, :bind3, :bind4, :bind5, :bind6, :bind7, :bind8, to_date(:bind9 ,'Y/m/d'))"; 
    $stid = oci_parse($conn, $query);

    oci_bind_by_name($stid, ":bind1", $year);
    oci_bind_by_name($stid, ":bind2", $month);
    oci_bind_by_name($stid, ":bind3", $empID);
    oci_bind_by_name($stid, ":bind4", $dptCode);    
    oci_bind_by_name($stid, ":bind5", $salHD);
    oci_bind_by_name($stid, ":bind6", $description);
    oci_bind_by_name($stid, ":bind7", $amount);
    oci_bind_by_name($stid, ":bind8", $optID);
    oci_bind_by_name($stid, ":bind9", $trDate);  //it is line 46
    $r = oci_execute($stid);  //it is line 47

Please tell me where I made a syntax error in the Oracle date conversion.

Replace this Statement

$query = "INSERT INTO PAYROLLFILE VALUES (:bind1, :bind2, :bind3, :bind4, :bind5, :bind6, :bind7, :bind8, to_date(:bind9 ,'Y/m/d'))";

with this query

$query = "INSERT INTO PAYROLLFILE VALUES (:bind1, :bind2, :bind3, :bind4, :bind5, :bind6, :bind7, :bind8, to_date(:bind9 ,'YY/mm/dd'))";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM