0

Changing the question in the hope of success...

I have an oracleDB class that begins...

class oracleDB {
  private $connec, $affectedRows, $parseStatement; 
  public $err;

  function __construct($user,$pwd,$db){
    $this->connec = OCILogon($user, $pwd, $db);
    if ( ! $this->connec ) {
      return false;
    }
  }

  function parse($sql){
    $operation = strtolower(substr(ltrim($sql), 0, 6));
    //update and delete must have where clause
    if($operation == "update" || $operation == "delete"){
      if(!stripos($sql, "where")){
        $this->err = "Update or delete query with no where clause!";
          return false;
        }
    }

    $this->parseStatement = oci_parse($this->connec, $sql);
    if ($this->parseStatement){
      var_dump($this->parseStatement);
      return true;
    } else {
      return false;
    }
  }//parse
}

I can connect to oracle and get data back using a simple connect string and select * statement.

However when i pass the connection to a variable

$conn_test = new OracleDB($user,$pwd,$db);

and then use and include('somefile.php');

and another class

class SomeOtherClass{

   function somemethod() {
     global $conn_test;

     $sql='select * from foobar';

     $conn_test->parse($sql);

     //...
   }
}

I get a fatal error on parse (on a non object)

$conn_test appears to lose it's value (is NULL) and i can't parse my query / return data

  • I have tried passing the $conn_test into the method as a variable, but this doesn't seem to work either.

Why this error appears?

diziaq
  • 6,881
  • 16
  • 54
  • 96
  • Check this link.. http://stackoverflow.com/questions/6894558/ora-12560-tnsprotocol-adaptor-error – Rahul Kaushik May 16 '14 at 12:49
  • yes i had read that, but i can connect to oracle and get data back, so not sure this applies in this instance. thanks –  May 16 '14 at 12:55

2 Answers2

1

There's a lot of dressing on your question - but what it boils down to is that you created an instance of an object and then were unable to access that instance.

Did you create the object in the global context? I suspect not.

Try changing

 $conn_test = new OracleDB($user,$pwd,$db);

to...

 global $conn_test;
 $conn_test = new OracleDB($user,$pwd,$db);

This also rather implies flaws in your diagnosis; there are subtle differences between isset(), isnull() and empty() and the stringified output of undefined variables.

symcbean
  • 47,736
  • 6
  • 59
  • 94
1

First, are you sure that $conn_test is defined? Before the class declaration, check it via echo isset($conn_test) && $conn_test instanceof OracleDB. This just to make sure that it was not defined inside of a function/class, which wouldn't give it the visibility you want.

If it IS there, you can try accessing it via $GLOBALS['conn_test']. It may also be possible that some other logic is unsetting your variable.

charmeleon
  • 2,693
  • 1
  • 20
  • 35