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.
--
PHP General 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]