Development PHP mysql Abstraction Layer

Discussion in 'Software' started by ST8, 31 Mar 2005.

  1. ST8

    ST8 What's a Dremel?

    Joined:
    14 Feb 2003
    Posts:
    596
    Likes Received:
    0
    I've been meaning to write this for ages, might prove useful to someone. Bassicaly a mysql interface class for php

    It uses placeholders (?) for user data so that it can be escaped prior to feeding into mysql, so should hopefully be relativly secure

    http://code.q3f.org/class.mysql.phps

    Examples:

    PHP:
    require_once('class.mysql.php');

    $db = new mysql(array( user => 'username',
                           
    pass => 'password',
                           
    db   => 'database',
                          )
                    );


    $data = array( table   => 'members',
                   
    columns => array('username''password''id'),
                   
    where   => "username LIKE ?",
                   
    order   => '? asc',
                   
    limit   => '4,2',
                   
    exec    => array('%s''username'),
                  );

    print_r($db->select($data));

    $data = array( table   => 'announcements',
                   
    columns => array('title''forum''announcement'),
                   
    exec    => array('test announcement'1'lalalal'),
                  );

    print 
    $db->insert($data) . " rows affected";


    $data = array( table   => 'announcements',
                   
    set     => array('title''forum'),
                   
    where   => 'id=?',
                   
    exec    => array('different test''4' ,1),
                  );

    print 
    $db->update($data) . " rows affected";

    $data = array( table   => 'announcements',
                  );

    print(
    $db->delete($data) . " rows affected";

    $data = array( query => 'select * from members order by ? asc limit 5',
                   
    exec  => array('username'),
                  );

    print_r($db->query($data));

    $db->destroy();
    Error handling is a little rough and ready ie the script dies if it encounters one ;)
    Comments / criticisms / suggestions would be appreciated
     
    Last edited: 22 Jan 2007
  2. RTT

    RTT #parp

    Joined:
    12 Mar 2001
    Posts:
    14,120
    Likes Received:
    74
    I lost this file a while back - but remember it was neat. Any chance of having it back? :D
     
  3. hitman012

    hitman012 Minimodder

    Joined:
    6 May 2005
    Posts:
    4,877
    Likes Received:
    19
    :thumb: Nice work, I also intended to write one of these classes so that custom error handling could be implemented on each query's execution while being editable from a single file.

    The only problem being that I would have to replace all the existing queries :sigh:
     
  4. OneSeventeen

    OneSeventeen Oooh Shiny!

    Joined:
    3 Apr 2002
    Posts:
    3,454
    Likes Received:
    2
    I'm getting a "403: Forbidden" from your .phps file, any chance of that being sorted soon? This looks kind of cool.

    I've written a few of these for microsoft access, but now that I'm an open source hippie I haven't touched it in months.

    Have you thought of posting this on sourceforge or something similar, so people could provide updates? I see this as being a very cool tool, but I'd want to play with it and try to make a few enhancements, such as incorporating various types of joins.

    Looks cool though! :thumb:
     
  5. TheAnimus

    TheAnimus Banned

    Joined:
    25 Dec 2003
    Posts:
    3,214
    Likes Received:
    8
    access databases need to be burnt on site.

    Now your an open source hippie thou, why not bring em to the masses, if you can make a standardized interface for MySQL MSSQL and MSACCESS that would be really narly!

    (failing that check C-omega, i don't know if its an ECMA standard yet, i belive there trying to make it, you can compile it with PHP via phlanger)
     
  6. Hwulex

    Hwulex Minimodder

    Joined:
    1 Feb 2002
    Posts:
    4,007
    Likes Received:
    1
    http://adodb.sourceforge.net/

    Works with
    For PHP and Python. Available as include files in PHP, or pre-compiled C. teh speed! :D
     
  7. ST8

    ST8 What's a Dremel?

    Joined:
    14 Feb 2003
    Posts:
    596
    Likes Received:
    0
    Am half way round the world atm and am having problems with my hosting, will try and sort it when i get back :)
     
  8. ST8

    ST8 What's a Dremel?

    Joined:
    14 Feb 2003
    Posts:
    596
    Likes Received:
    0
    This should be back up now...
     

Share This Page