Select/Where with parameter does not work on Oracle

Asked

Viewed 512 times

0

I am making a select with Where via PHP and Oracle, when it receives an error by the parameter occurs:

Warning: oci_execute(): ORA-00911: invalid Character in C: xampp htdocs project includes Read.php on line 52 Warning: oci_fetch_array(): ORA-24374: define not done before fetch or execute and fetch in C: xampp htdocs projeto index.php on line

If I pass the direct parameter works normally, as commented line, it works.

public function readAnexos($CDLICITACAO) {

    try{
        //$id = '012103';
        $id = $CDLICITACAO;

            $sql_query = "SELECT * FROM TBLICITCAO WHERE CDLICITACAO = $id";
            $stid = oci_parse($this->db, $sql_query);

            oci_execute($stid);
            return $stid;

        }

    catch (Exception $e){
        echo $e->getMessage() . "<br>Error na linha:  ";
        echo "<b>" . $e->getTraceAsString()."</b>";
        parent::fechar();
    }
}

2 answers

0

The problem is in the identification of $id, is not passing the variable but string '$id' to be compared with a probably whole field.

To solve your problem replace the query line with:

$sql_query = "SELECT * FROM TBLICITCAO WHERE CDLICITACAO = ".$id;
  • (80) "SELECT * FROM TBLICITCAO WHERE CDLICITACAO = 014384" Warning: oci_execute(): ORA-00911: invalid Character in C: xampp htdocs project includes Read.php on line 48 Warning: oci_fetch_array(): ORA-24374: sets not done before fetch or execute and in C:xampp htdocs project index.php on line 72

  • Code for lines 48 and 72?

  • Read.php oci_execute($stid); index.php while ($Row = oci_fetch_array($stid)) {&#xA; $dataAnexos[] = array("IDANEXO" => $row['IDANEXO'],&#xA; "CDLICITACAO" => $row['CDLICITACAO'],&#xA; "NARQUIVO" => $row['NARQUIVO'],&#xA; "DIRARQUIVO" => $row['DIRARQUIVO']);&#xA;}

  • @Andrec Is the name of the table (TBLICITACAO) and the name of the field (CDLICITACAO) higher in the bd? If they are minute, try going to minuscule in php and see if something changes.

  • They are all uppercase... the funny thing is that only I change the $id = 013203 works... if I leave the parameter not... but the parameter is coming correctly tb. the column in the bank is VARCHAR2(6 BYTE)

0

Even though it didn’t work, it generated an error... but the sql is correct, if I run it in the database, it works.

string(80) "SELECT * FROM TBLICITCAO WHERE CDLICITACAO = 014384"

Warning: oci_execute(): ORA-00911: invalid Character in C: xampp htdocs project includes Read.php on line 48

Warning: oci_fetch_array(): ORA-24374: define not done before fetch or execute and fetch in C: xampp htdocs projeto index.php on line 72

Browser other questions tagged

You are not signed in. Login or sign up in order to post.