connect() vs. pconnect()

From: Date: Thu, 05 Jul 2001 04:53:28 +0000
Subject: connect() vs. pconnect()
Groups: php.general 
Request: Send a blank email to php-general+get-56262@lists.php.net to get a copy of this message
Hi, I need some help with a class that I am writing. class myclass { function query($query) { // connect $connection = mysql_connect($this->hostname, $this->user, $this->pass) or die ("Cannot connect to database"); // run query $ret = mysql_db_query($this->db, $query, $connection) or die ("Error in query: $query"); // return result identifier return $ret; } // function: get label for $id // returns: string function get_label($id) { $query = "SELECT label FROM $this->table WHERE id = '$id'"; $result = $this->query($query); $row = mysql_fetch_row($result); return $row[0]; } // function: get link for $id // returns: string function get_link($id) { $query = "SELECT link FROM $this->table WHERE id = '$id'"; $result = $this->query($query); $row = mysql_fetch_row($result); return $row[0]; } // function: execute query $query // returns: result identifier } In this class, I have a query() method which accepts a query and returns a result identifier. All the other class methods use this to run SQL queries. Now, if I had the following code: <? $a = new myclass(); echo "<a href=" . $a->get_link(29) . ">" . $a->get_label(29) . "</a>"; ?> Would two different connections be opened to the DB for the two method calls? If so, is this optimal? I suspect it is not. Someone has suggested using mysql_pconnect() in my query() method - is this better? Why? If I use pconnect() - how and when will the connection close? Does this happen automatically? TIA, Vikram -- I took an IQ test, and the results were negative.

« previous php.general (#56262) next »