Re: Loss of connection handle object

From: Date: Fri, 02 Mar 2001 01:23:05 +0000
Subject: Re: Loss of connection handle object
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-42264@lists.php.net to get a copy of this message
Perhaps if you showed us some code? Best regards, Andrew On 3/1/01 7:35 PM, "Andrew Halliday" <andrew@recalldesign.com> wrote: > open() is simply supposed to open the connection to the database and store > it in $this->connection. > As you can see - it gets the connection info from either the objects > properties or from parameters passed to it. > Can you see what Ive done wrong...if anything?!?! > > AndrewH > > ----- Original Message ----- > From: "Andrew Hill" <ahill@openlinksw.com> > To: "Andrew Halliday" <andrew@recalldesign.com>; > <php-general@lists.php.net> > Sent: Friday, March 02, 2001 11:13 AM > Subject: Re: [PHP] Loss of connection handle object > > >> Andrew, >> >> What is the open() function? >> >> Best regards, >> Andrew >> --------------------------------------- >> Andrew Hill - OpenLink Software >> Director Technology Evangelism >> eBusiness Infrastructure Technology >> http://www.openlinksw.com >> >> >> >> >> On 3/1/01 7:27 PM, "Andrew Halliday" <andrew@recalldesign.com> wrote: >> >>> 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 ... >>> >>> HELP! >>> >>> Thanx in advance, >>> AndrewH >>> >>> ------------------------------------------------------------- >>> 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, >>> $database) >>> { >>> 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, >>> $database); >>> } >>> >>> 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; >>> else >>> 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); >>> } >>> >>> /*PRIVATE FUNCTIONS:*/ >>> function getRow($row) >>> { >>> return pg_fetch_array($this->lastResultSet,$row); >>> } >>> >>> function getResultLength() >>> { >>> return count($this->lastResultSet); >>> } >>> } >>> >>> >>> >>> >> >

« previous php.general (#42264) next »