Using custom SQL functions to call either ms... or my... depending on server

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • David Walker

    #1

    Using custom SQL functions to call either ms... or my... depending on server

    Hi again
    As I'm developing my site, i've come across a problem with the database use.
    While developing it I only have mySQL, but the final server has msSQL. I
    was thinking about using all my own functions (ie sql_query), which would be
    a function in an include file which would either call mysql_query or
    mssql_query depending on the server (i'd have two different include files
    for this).
    Has anyone done this before, do you know of any drawbacks, or are there any
    problems i'm likely to come across? I'm hoping speed won't be an issue,
    since its just calling a function which does the exact same job.
    Heres what I had in mind:

    ####### in the main file #########
    $query = "SELECT * FROM .....";
    $result = sql_query($quer y);
    $num = sql_num_rows($r esult);
    ############### ############

    ##### include file, for mysql ######
    function sql_query($sqlq uery)
    {
    $result = mysql_query($sq lquery);
    return $result;
    }

    function sql_num_rows($s qlresult)
    {
    $num = mysql_num_rows( $sqlresult);
    return $num;
    }
    ############### ###############



    I've just made this up off the top of my head so there may be the odd
    mistake, but does the idea look right? I'd have another very similar file
    for mssql_.....

    David



  • Bruno Desthuilliers

    #2
    Re: Using custom SQL functions to call either ms... or my... dependingon server

    David Walker wrote:[color=blue]
    > Hi again
    > As I'm developing my site, i've come across a problem with the database use.
    > While developing it I only have mySQL, but the final server has msSQL. I
    > was thinking about using all my own functions (ie sql_query), which would be
    > a function in an include file which would either call mysql_query or
    > mssql_query depending on the server (i'd have two different include files
    > for this).
    > Has anyone done this before,[/color]

    Yes... BTW, I think the PEAR::db module does it already, so you may not
    have to reinvent the square wheel.
    [color=blue]
    > do you know of any drawbacks, or are there any
    > problems i'm likely to come across?[/color]

    The main problem is that each SQL engine support its own subset of the
    SQL standard, and usually with some non-standard additions to it. So you
    have to be careful that all your SQL queries work for both engines.
    [color=blue]
    > I'm hoping speed won't be an issue,[/color]

    You'll more probably have speed issues coming from the database itself.

    (snip)

    HTH
    Bruno

    Comment

    • David Walker

      #3
      Re: Using custom SQL functions to call either ms... or my... depending on server

      > Yes... BTW, I think the PEAR::db module does it already, so you may not[color=blue]
      > have to reinvent the square wheel.[/color]

      No idea if I have this, or how to use it :o\ I assume its not part of a
      default PHP install with the Windows installer (which doesn't have much),
      which is all the final server has installed. Its primarily a Windows server
      with ASP - they say they just put PHP on as it is, and won't give any
      support for additional modules. Thats is where the problems in my previous
      post came from.
      [color=blue]
      > The main problem is that each SQL engine support its own subset of the
      > SQL standard, and usually with some non-standard additions to it. So you
      > have to be careful that all your SQL queries work for both engines.[/color]

      Yeah - i'll be checking carefully as I do it that there are equivalent
      functions for both. I'm not doing anything hugely complicated, so I don't
      suppose it'll be an issue. I'll watch out for it though.
      [color=blue][color=green]
      > > I'm hoping speed won't be an issue,[/color]
      > You'll more probably have speed issues coming from the database itself.[/color]

      Thought as much. Doesn't matter too much, as long as i'm not losing a lot
      of extra speed by doing it this way I don't mind - it'll only have around
      150 users max anyway (although the database does hold a lot of information,
      but still shouldn't be an issue)

      Thanks

      David


      Comment

      • David Walker

        #4
        Re: Using custom SQL functions to call either ms... or my... depending on server

        > bad server. Burn server, get another one.

        Nowt to do with me unfortunately - we get a server to use, thats the one we
        use... Its for a University sports club, so we get space on their server -
        much better than anything else with adverts popping up, and they don't let
        us use our money (which they give us) to pay for separate hosting.
        [color=blue]
        > Now AFAIK, PEAR is just a PHP lib, not an extension module, so you just
        > have to copy the parts you want somewhere on your include path (use
        > phpinfo() to have more infos about the final server php config).[/color]

        Nah we don't have access to any of the include directories, and I don't
        suppose they'll do it for me. Last time I asked them to do something was
        update GD lib, they ended updating the whole PHP version and broke it!
        [color=blue]
        > BTW, just one silly question : why don't you just install mSql on your
        > computer ?[/color]

        Well I've been getting round to doing that... really :o\ I got the
        Enterprise version but it wouldn't install on XP (as far as I could tell -
        told me it wouldn't, but it looks like theres something there...). I'm
        getting the Personal version, so see if that works.
        Incidentally I might still use this function since I have been trying to get
        a mySQL database on a different University server - if that does ever come
        through then it'll be easier to change over - equally if they ever change
        their server.

        David


        Comment

        • David Walker

          #5
          Re: Using custom SQL functions to call either ms... or my... depending on server

          > No, no trouble with this. I meant the *PHP* include path, the one that[color=blue]
          > is in the php.ini. It can be (and is frequently) a subdirectorie of your
          > web root directory. No messing with extensions modules, libraries etc...[/color]

          Not sure. From PHPinfo the only include path is c:\php4\pear (although
          "pear" in the name sounds very promising!), but if that is not it there is
          nothing I can access in webroot - we have a single directory within that,
          and theres nothing in PHPinfo that points to any include dirs being within
          our own directory.

          Anyway, i've got the functions working OK that I need now - I only need (so
          far anyway) query, num_rows and fetch_array, all of which are the same
          between mysl and mssql except the the one letter difference. It should
          work, but i've just noticed that, as well as breaking GD, they also managed
          to lose the mssql extension, so I can't test anything at the minute! I
          really want our own server now!!! :o(

          So, I think i'll just leave pear - everything is working (well, as much as I
          can make work myself), and I don't really know what pear is, but don't
          suppose it'll make much difference to what I need to do.
          Thanks for the help though

          David


          Comment

          Working...