View Single Post
Old 06-12-2010, 05:04 PM   #1 (permalink)
pipesportugal
The Contributor
 
pipesportugal's Avatar
 
Join Date: May 2008
Location: Oporto-Portugal
Posts: 32
Thanks: 11
pipesportugal is on a distinguished road
Default Connecting to database everytime You make an instance

Hello dear colleagues from the TalkPHP forum,

I am trying to build a class to read the content of all my tables.
I am calling this class record.

Everytime I create an instance of this class I am sending all the database information on the "new" sentence, meaning:

PHP Code:

$customer 
= new record("$hostname""$user_db""$pass_db""$database","$record_to_pick","$table_name"); 
Inside the class I am performing everytime all the normal operations of accessing a database, meaning:

PHP Code:

public function __construct($host,$username,$password,$db,$recordtopick,$tablename)
{
$this->host         $host;
$this->username     $username;
$this->password     $password;
$this->db           $db;
$this->recordtopick $recordtopick;
$this->$tablename   $tablename;
$this->conectar();


private function 
conectar()
{
$this->link mysql_connect($this->host$this->username$this->password);
mysql_select_db($this->db$this->link);

Most of the times, even in a very small program I am using this class many times to read several tables.

My questions are:
1) Is the fact of using this class so often, therefore connecting to the database so many times, making my programs slow down?
2) If so, how can I improve my programs?

Thanks in advance for all replies,
PP
pipesportugal is offline  
Reply With Quote