Need help removing ORA-00911 error while using oci_execute()

2.9k Views Asked by At

I am using following code to generate the SQL.

$sql = "INSERT INTO SUBSTATION VALUES (".
            "SEQ_SUBSTATION_FEATURE_ID.NEXTVAL, ".
            "'".$_REQUEST['substationName']."', ".  // SUBSTATION NAME
            "null, ".                               // SLD_PATH       
            "null, ".                               // GEOMETRY
            "'".$_REQUEST['substationType']."', ".  // SUBSTATION_TYPE
            $_REQUEST['capacity'].", ".             // CAPACITY
            "'".$_REQUEST['address_1']."', ".       // ADDRESS_1
            "'".$_REQUEST['address_2']."', ".       // ADDRESS_2
            "'".$_REQUEST['landmark']."', ".        // LANDMARK
            "'".$_REQUEST['state']."', ".           // STATE
            "'".$_REQUEST['district']."', ".        // DISTRICT
            "'".$_REQUEST['pin']."', ".             // PIN
            $_REQUEST['noOfTransformers'].", ".     // NO_OF_TRANSFORMERS
            $_REQUEST['noOfLTBreakers'].", ".       // NO_OF_LT_BREAKERS
            $_REQUEST['noOfHTBreakers'].", ".       // NO_OF_HT_BREAKERS
            $_REQUEST['noOfHTIsolators'].", ".      // NO_OF_HT_ISOLATORS
            $_REQUEST['noOfLTBoards'].", ".         // NO_OF_LT_BOARDS
            "to_date('".$_REQUEST['commissioningDate']."','DD/MM/YYYY'), ". // COMMISSIONING DATE
            "'".$_REQUEST['schemeNo']."', ".        // SCHEME_NO
            "to_date('".$_REQUEST['schemeDate']."','DD/MM/YYYY'), ".        // SCHEME_DATE
            "'".$_REQUEST['comments']."', ".        // COMMENTS
            "'N', ".                                // APPROVED
            "null, ".                               // APPROVER
            "null);";                               // APPROVED_ON

Here is the SQL generated

INSERT INTO SUBSTATION VALUES 
(SEQ_SUBSTATION_FEATURE_ID.NEXTVAL, 'S/S 3 4400', NULL, NULL, 'D', 5000, 
'The Address 1', 'The Address 2', 'The Landmark', '15', '1', '234234', 
34, 65, 12, 98, 43, 
to_date('01/09/2010','DD/MM/YYYY'), 'Scheme 12345', 
to_date('06/10/2010','DD/MM/YYYY'), 'This substation has following assets', 
'N', null, null);

Now, I run the SQL generated directly in SQL Developer, it works fine. But when I run the query using oci_execute($sql) in PHP, it does not work. While debugging using the following code:

$st = oci_parse($conn, $sql) or die("<br />Error parsing query. ");  
if(!oci_execute($st)){  
  $err = oci_error($st);  
  echo $err['message'];  
}

It show the error message:

ORA-00911 : illegal character

Any help please.......

2

There are 2 best solutions below

1
On

I solved the problem by using oci_bind_by_name to prepare the statement. Please refer the this link...

Inserting data in oracle database using php

I got rid of ORA-00911. This time, error ORA-01461, which is invalid month, while inserting date. Following link solved the problem...

[Resolved] ORA-01461 Error on ocibindbyname

Thanks

1
On

Remove the semi-colon at the end of the generated SQL statement and try again.