This is what i've been doing for that last while, and i think i've finally got all the bugs worked out. after you load the class, do

stream_wrapper_register('db','db_wrapper');

then

fopen('db://dbtype/user:pw@host/dbname.tables/options');

where

dbtype := "mysql" | "pgsql" | "sqlite" | ("oci8" | "oracle") | ("sybase" |
          "sybasect" | "sybase-ct") | "mssql" | "fbsql" | "odbc"

user := regex( /[\w.]+/ )

pw   := regex( /[\x21-\x7e]/+ | "" )

host := regex( /[\w.-]+/ )

dbname := regex( /[\w-]+/ )

tables := table_name["=" table_alias]["," ...]
    table_name := regex( /\w+/ )
    table_alias := regex( /\w+/ )

options := columns | where | order | group
    columns := "columns=" column_part["," ...]
        column_part := col_name["=" col_alias]
            col_name := regex( /[\w.]/ ) | "*"
            col_alias := regex( /[\w.]/ )
    where := "where=" '"' regex( /.*?/ ) '"'
    order := "order=" (col_name ["|" direction])["," ...]
        direction := "asc" | "desc"

hope that makes it easy to understand the syntax.

stat() is unsupported, as is unlink() as of yet. feof(), fseek(), read and write funcs are supported. full cleanup included.

also there's a poll.... do you think i should keep posting my useless work of shut up about it? [edit]2 week timeout on the poll[/edit]

    no replys, not even a vote to tell me i suck, and only one person's downloaded it.... you guys are really not interested! i guess i really should stop posting these stupid things...

      Hey Moonglobe!

      Coooooool code! What the f*$% does it do?

      Norm

        it's for accessing a database through the filesystem functions. guess i shoulda said that, but after bein immersed in the code for 3 days, guess u just start to asmue things....

          Nice code man. Couple things should just be mentioned. Now, granted, I did for the most part "scan" over it, so just call me out if I'm wrong.

          1) It's utilizing dbx functions, which aren't installed by default. May want to do a check to make sure they are installed first.

          2) You utilize some functions that aren't enabled in all database types(LIMIT comes to mind). For those specific functions, you should do a check for DB type.

          I know to tackle a truely universal DB wrapper is a massive untertaking if you want to include all functionality(joins, subquerys, stored procedures, etc, etc), so this looks like a good start. Nice work 🙂

            i knew about limit already, and i've decided to take it out. i'm doing a seperate wrapper for each database type now (which is going to take a hell of a lot of research) and i hope to take db:// to the next level as a metawraooer, not needing the database type specified and guessing. the only problem i'm running into here is, what to default to? perhaps i could switch the DB type over to a mode setting...

            PS in the above open syntax group is exactly the same as order.

              I'm pretty versed in most databases. Though, there are definately more qualified people on here than I, feel free to PM me if you have any sort of questions. I'd be glad to help....

                here's the new version, with limit taken out, a bit in the constructor to try and load the module if its not there or die, and some error functionality i'd forgotten to implement (stream_read() now returns a substr of $this->_error, if it exists, or at least 4 bytes of it ("ERR:"))

                  ok guys, here's the newest version. still uses DBX. write support is being rewritten. unlink() is now supported (make sure you add a /where="blah"/ to the path or it cuts the whole table!). have fun, and write support should be up soon (will be an UPDATE query).

                    Write a Reply...