我是Oracle数据库的新手。我在Oracle中创建了一个表。我可以使用PHP $_POST[]
从HTML中获取一些价值,并且连接正常。
现在我想将当前日期从PHP存储到Oracle表中作为日期类型。但是我不知道绑定Date的正确方法,我收到了这个错误:
以下是代码:
$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
请告诉我在Oracle日期转换中出现语法错误的位置。
答案 0 :(得分:2)
替换此声明
$query = "INSERT INTO PAYROLLFILE VALUES (:bind1, :bind2, :bind3, :bind4, :bind5, :bind6, :bind7, :bind8, to_date(:bind9 ,'Y/m/d'))";
使用此查询
$query = "INSERT INTO PAYROLLFILE VALUES (:bind1, :bind2, :bind3, :bind4, :bind5, :bind6, :bind7, :bind8, to_date(:bind9 ,'YY/mm/dd'))";