To abstract or not

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
A ways back I setup my db access PHP file to support either MySQL or MSQL.
Now, I am sticking w/MySQL. For performance reasons, should I replace my
generic functions w/the raw MySQL ones ?

For example, I had this (from PHPNuke):

function sql_connect($host, $user, $password, $db)
 global $dbtype;
 switch ($dbtype)
  case "MySQL":
   $dbi = @mysql_connect($host, $user, $password);
   return $dbi;

  case "mSQL":
   $dbi = msql_connect($host);
   return $dbi;


and now I can just use mysql_connect instead of going through the extra file
and functions and calling sql_connect.

Comments ?

Re: To abstract or not

m|sf|t wrote:

Quoted text here. Click to load it

The code you posted isn't likely to generate a significant load compared
with, say actually retrieving data from the database - definitely not worth
bothering about for perfomrance reasons.



Re: To abstract or not

Quoted text here. Click to load it

Do you expect your project to grow and change? Where do you think it
will be in two years? Will you have to adapt it to other databases in
the future? Are there side-benefits to the abstraction, like allowing
rich error messages, or catching function calls that shouldn't be made
because of a previous error? Will you be adding new features?

Abstraction is an insurance policy. You want that insurance against
future change, if you think your project is going to change. It is
slightly expensive in terms of performance. Ask yourself if your
project needs that insurance.

Re: To abstract or not

Quoted text here. Click to load it

   Abstraction is obviously an overhead, but there is large benefits
when your project grow or you want to change your DB. So, I always
prefer abstraction like the one used by phpBB; the above is tooooo

  <?php echo 'Just another PHP saint'; ?>
Email: rrjanbiah-at-Y!com

Site Timeline