Okay - Im writing an object to wrap a database.
The key problem is this:
    - it declares a connection var as an object property
    - the open() function opens the connection to the database and stores
the handle in $this->connection
    - the executeQuery() method complains about not having a valid handle,
because by then, somehow, $this->connection==null!!!

Any ideas?-i swear its just something stupid ive missed ...


Thanx in advance,

The code following this returns the following to the browser:
The connection in open() is :Resource id #1
The connection in executeQuery() is :''

Warning: Supplied argument is not a valid PostgreSQL link resource in
/var/wwwroot/php/PostgreSQLDataSource.php on line 67


class PostgreSQLDataSource
   var $connection;
   var $lastResultSet;
   var $error_handler;

   var $host, $port, $username, $password, $database;

   function PostgreSQLDataSource($host, $port, $username, $password,
      global $error_handler;
      $this->error_handler = $error_handler;

      $this->host = $host;
      $this->port = $port;
      $this->username = $username;
      $this->password = $password;
      $this->database = $database;

      //Legacy behaviour: $this->open($host, $port, $username, $password,

   function open(/*variable arg list*/)
      $connectionString = "";

      if (func_num_args() == 5)
         $this->host = func_get_arg(0);
         $this->port = func_get_arg(1);
         $this->username = func_get_arg(2);
         $this->password = func_get_arg(3);
         $this->database = func_get_arg(4);

      if ($this->host)
         $connectionString .= " host=".$this->host;
      if ($this->port)
         $connectionString .= " port=".$this->port;
      if ($this->username)
         $connectionString .= " user=".$this->username;
      if ($this->password)
         $connectionString .= " password=".$this->password;
      if ($this->database)
         $connectionString .= " dbname=".$this->database;

      $this->connection = pg_Connect($connectionString);
echo "The connection in open() is :".$this->connection."<BR>";
      if ($this->connection == false)
         return false;
         return true;

   function close()
      return pg_Close($this->connection);

   function executeQuery($queryString)
echo "The connection in executeQuery() is :'".$this->connection."'<BR>";
      $this->lastResultSet = pg_exec($this->connection,$queryString);
      return new Iterator($this);

   function getRow($row)
      return pg_fetch_array($this->lastResultSet,$row);

   function getResultLength()
      return count($this->lastResultSet);

PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to