oci_bind_by_name and to_date PHP/OCI/Oracle

前端 未结 1 1613
闹比i
闹比i 2020-12-20 18:55

I have the following:

    $ARTIFACT_NAME = $_POST[\'ArtifactName\'];
    $ARTIFACT_TYPE = $_POST[\'ArtifactType\'];
    $ARTIFACT_LOCATION = $_POST[\'Artifac         


        
相关标签:
1条回答
  • 2020-12-20 19:33

    You're using an Oracle statement with bound parameters. That's good because it prevents SQL injections where dangerous code is inserted into your SQL statement. However, in this case, it prevents the TO_CHAR function from being executed. Instead, it tries to convert the whole string into a timestamp, which of course doesnt' work.

    The solution is rather straight-forward: move to TO_CHAR function away from the bound parameter directly into the statement:

    $REGISTERED_TIMESTAMP = "15-08-2011 14:32:37";
    
    $query =    "INSERT INTO ".$db_schema.".ARTIFACTS (ARTIFACT_ID, ARTIFACT_NAME, ARTIFACT_TYPE, ARTIFACT_LOCATION, ARTIFACT_DOMAIN, ARTIFACT_AUTHOR, ARTIFACT_LABEL, AUDIT_CONSTRAINTS, SECURITY_CONSTRAINTS, REGISTERED_EMAIL, REGISTERED_TIMESTAMP)
                VALUES (:bind1, :bind2, :bind3, :bind4, :bind5, :bind6, :bind7, :bind8,
                   :bind9, :bind10, to_date(:bind11, 'DD-MM-YYYY HH24:MI:SS'))";
    
    0 讨论(0)
提交回复
热议问题