To abstract or not

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • m|sf|t

    To abstract or not

    All,
    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($ho st, $user, $password, $db)
    {
    global $dbtype;
    switch ($dbtype)
    {
    case "MySQL":
    $dbi = @mysql_connect( $host, $user, $password);
    return $dbi;
    break;;

    case "mSQL":
    $dbi = msql_connect($h ost);
    return $dbi;
    break;;

    default:
    break;;
    }
    }

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

    Comments ?


  • Colin McKinnon

    #2
    Re: To abstract or not

    m|sf|t wrote:
    [color=blue]
    > All,
    > 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 ?
    >[/color]

    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.

    HTH

    C.

    Comment

    • lawrence

      #3
      Re: To abstract or not

      "m|sf|t" <m|sf|t@ampsych o.com> wrote in message news:<10q00gemj k2jb2c@corp.sup ernews.com>...[color=blue]
      > All,
      > 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 ?
      >[/color]

      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.

      Comment

      • R. Rajesh Jeba Anbiah

        #4
        Re: To abstract or not

        "m|sf|t" <m|sf|t@ampsych o.com> wrote in message news:<10q00gemj k2jb2c@corp.sup ernews.com>...[color=blue]
        > All,
        > 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($ho st, $user, $password, $db)
        > {
        > global $dbtype;
        > switch ($dbtype)
        > {
        > case "MySQL":
        > $dbi = @mysql_connect( $host, $user, $password);
        > return $dbi;
        > break;;
        >
        > case "mSQL":
        > $dbi = msql_connect($h ost);
        > return $dbi;
        > break;;
        >
        > default:
        > break;;
        > }
        > }[/color]

        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
        overhead.

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

        Comment

        Working...