06-13-2010, 06:55 PM
|
#2 (permalink)
|
|
Wizard
Join Date: Sep 2007
Posts: 1,299
Thanks: 17
|
Quote:
Originally Posted by pipesportugal
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
|
It shouldn't be a problem, use mysql_pconnect to pool your connection so that don't have to continually reopen connections. Basically what that function does it it looks for a presistant connection to open with before creating one.
|
|
|
|