TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
 
 
LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
Old 06-12-2010, 05:04 PM   #1 (permalink)
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
 



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to use the Singleton design pattern Karl Advanced PHP Programming 27 10-22-2012 08:16 AM
Question | There is a way to make merged login config.php?? (MSSQL+MySQL) FrozenGod Absolute Beginners 1 11-06-2009 07:52 AM
Using the factory pattern (mad rantings of a mind without coffee) sketchMedia Advanced PHP Programming 35 09-25-2009 11:05 AM
[Tutorial] How to organize your classes | Part 1 Tanax Advanced PHP Programming 10 03-01-2009 10:08 PM
Adding Images to a database from a folder Rendair Advanced PHP Programming 3 01-13-2008 07:40 PM


All times are GMT. The time now is 03:00 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design