简体   繁体   English

PHP Oracle SQL选择日期to_char

[英]PHP Oracle SQL Select date to_char

I am getting; 我正进入(状态; "Warning: oci_execute(): ORA-00904: "JAN": invalid identifier ", when I try to execute these commands: 当我尝试执行以下命令时, "Warning: oci_execute(): ORA-00904: "JAN": invalid identifier ”:

function stime($conn3, $time){

    $result = oci_parse($conn3, "SELECT TO_CHAR($time, 'mm/dd/yyyy') FROM MON_EVENTS")or die(oci_error());
    oci_execute($result);
}

STIME is also a date field in the database. STIME也是数据库中的日期字段。

I am passing the STIME field to $time as stime($row_oci['STIME']). 我将STIME字段$time as stime($row_oci['STIME']).传递给$time as stime($row_oci['STIME']).

You were bitten by PHP string interpolation : 您被PHP 字符串插值法所困扰

$result = oci_parse($conn3, "SELECT TO_CHAR($time, 'mm/dd/yyyy') FROM MON_EVENTS")or die(oci_error());
//                                          ^^^^^

$time is replaced by its content converted to a string -- and that before passing the value to the oci_parse function. $time被其内容转换为字符串 -以及将值传递给oci_parse函数之前的内容所代替。 As the string representation of a date might contain spaces, letters, / , ... it will confuse the Oracle SQL parser that report ORA-00904: Invalid identifier . 由于日期的字符串表示形式可能包含空格,字母, / ,...,因此会混淆报告ORA-00904: Invalid identifier的Oracle SQL解析器。

As of myself I would suggest to use bind parameter instead. 就我自己而言,我建议改用bind参数。 This is much less error-prone -- and much more safe : 这不容易出错-而且更安全

$result = oci_parse($conn3, "SELECT TO_CHAR(:time, 'mm/dd/yyyy') FROM MON_EVENTS");
oci_bind_by_name($result, ':time', $time);

$id = $row_oci['ID']; $ id = $ row_oci ['ID'];
$result = oci_parse($conn2, "SELECT TO_CHAR(STIME,'MON/DD/YY hh24:mm:ss') FROM MON_EVENTS WHERE ID = $id"); $ result = oci_parse($ conn2,“从ID为$ id的MON_EVENTS中选择TO_CHAR(STIME,'MON / DD / YY hh24:mm:ss')
oci_execute($result); oci_execute($ result);
while($row_result = oci_fetch_array($result)){ while($ row_result = oci_fetch_array($ result)){
echo "". 回显“”。 $row_result['0'] ."";} $ row_result ['0']。“”;}

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

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