Page 1 of 1

[RESOLVED] I need help with OCI8 oci_execute() error

Posted: Mon May 02, 2011 1:26 pm
by vaughtg
I have the following code in a class

Code: Select all

  private function deanonimize($sql){
    $newsql = "";
    $paramcount = 0;
    for ($i=0; $i<strlen($sql); $i++){
      $char = substr($sql, $i, 1);
      if ($char == '?'){
        $char = ":ph$paramcount";
        $paramcount++;
      }
      $newsql = $newsql.$char;
    }
    return $newsql;
  }

  private function bindToStatement($statement, $binds){
    $count = 0;
    foreach($binds as $var){
      $placeholder = ":ph$count";
      if(!oci_bind_by_name($statement, $placeholder, $var)){
        $this->setErrorMsg("- Error binding values in bindToStatement()");
        $this->setOciErrorMsg(oci_error($statement));
        $statement = false;
        break;
      }
      $count++;
    }
    return $statement;
  }

  private function getResultSet($query, $bindsArray){
    /*
     * receives a query, parses and executes that query, puts the result
     *  set into an array and returns that array to the calling method
     */
    $conn = $this->getConnection();
    if($conn){
      $query = $this->deanonimize($query);
      $stmt = oci_parse($conn, $query);
      if(!$this->bindToStatement(&$stmt, $bindsArray)){
        $this->setErrorMsg("- Error binding values to prepared statement in getResultSet()");
        return null;
      }
    }else{
      $this->setErrorMsg("No connection to the database.");
      return null;
    }
    if(oci_execute($stmt)){  // <-------------------- this is where I get the error
      $rowCount = oci_fetch_all($stmt, $resultsArray, null, null,
          OCI_FETCHSTATEMENT_BY_ROW+OCI_NUM);
    }else{
      $err = oci_error($stmt);
      $this->setOciErrorMsg($err);
      $resultsArray = array();
    }
    return $resultsArray;
  }
I am passing a query string and binds array to getResultSet(). The application was written for PDO, so when I had to change it over to OCI8, I had to find a way to use the prepared statements from the function calls designed for PDO, which led to the deanonimize() and bindToStatement() functions.

At the indicated line, I get an ORA-01460 error. "ORA-01460: unimplemented or unreasonable conversion requested" and I have no idea what is causing this. My output from oci_error():

Code: Select all

oci_error[code]=1460
oci_error[message]=ORA-01460: unimplemented or unreasonable conversion requested
oci_error[offset]=18
oci_error[sqltext]=select privs from dbusers where username = :ph0 and pword = :ph1
username and pword are both varchar2 and the values in the bindsArray are both strings, so I cannot figure out what is causing this error.

Anybody? Help?

:banghead:

No idea EXACTLY what I did, but I transferred all of my code from classes to the calling page and got it working. One thing I know I did was ensure that I was using my database connection instead of an instance of my DBConnection class when calling oci_parse(). There were a handful of other changes made in the process, but that was the biggie that I documented. I then slowly put it back into the original functions, reintroduced the function calls and it worked.