简体   繁体   English

警告:oci_execute():ORA-01821:日期格式无法识别

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

I am new to Oracle database. 我是Oracle数据库的新手。 I have created a table in Oracle. 我已经在Oracle中创建了一个表。 I can get some value from HTML using PHP using $_POST[] , and connection works fine. 我可以使用$_POST[]使用PHP从HTML中获得一些价值,并且连接工作正常。

Now I want to store current Date from PHP into an Oracle table as Date type. 现在,我想将PHP中的当前Date作为Date类型存储到Oracle表中。 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. 请告诉我在Oracle日期转换中我在哪里犯了语法错误。

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'))";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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