To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here
PHPBuilder.com  
 

 

Go Back   PHPBuilder.com > PHP Help > Code Critique

Code Critique Having someone critique your code is always a great way to hone the skills. Stop in and post your code to see what your peers may have done differently.

View Poll Results: Should i keep showing you guys my useless works?
Sure, they're interesting sometimes 1 100.00%
No, you suck, none of your work is original 0 0%
Voters: 1. You may not vote on this poll

Reply
 
Thread Tools Rate Thread Display Modes
Old 01-21-2004, 03:17 AM   #1
Moonglobe
Better fan than rebelo!
 
Moonglobe's Avatar
 
Join Date: Apr 2003
Location: brain://localhost:left-side
Posts: 2,381
DBX Stream Wrapper

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
PHP Code:
stream_wrapper_register('db','db_wrapper');
then
PHP Code:
fopen('db://dbtype/user:pw@host/dbname.tables/options');
where
Code:
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]
Attached Files
File Type: txt dbwrap.php.txt (14.1 KB, 86 views)
__________________
there's no place i can be, since i found serenity.

Last edited by Moonglobe; 01-23-2004 at 06:54 PM.
Moonglobe is offline   Reply With Quote
Old 01-22-2004, 12:13 AM   #2
Moonglobe
Better fan than rebelo!
 
Moonglobe's Avatar
 
Join Date: Apr 2003
Location: brain://localhost:left-side
Posts: 2,381
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...
__________________
there's no place i can be, since i found serenity.
Moonglobe is offline   Reply With Quote
Old 01-23-2004, 04:33 AM   #3
Norman Graham
Senior Member
 
Norman Graham's Avatar
 
Join Date: Nov 2002
Location: Berlin, Germany
Posts: 771
Cool Cool!

Hey Moonglobe!

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

Norm
__________________
39 years behind the times and counting
Norman Graham is offline   Reply With Quote
Old 01-23-2004, 11:34 AM   #4
Moonglobe
Better fan than rebelo!
 
Moonglobe's Avatar
 
Join Date: Apr 2003
Location: brain://localhost:left-side
Posts: 2,381
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....
__________________
there's no place i can be, since i found serenity.
Moonglobe is offline   Reply With Quote
Old 01-23-2004, 01:36 PM   #5
LordShryku
kung foo code monkey
 
LordShryku's Avatar
 
Join Date: Aug 2002
Location: Occupational Hypnotherapy
Posts: 7,473
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
LordShryku is offline   Reply With Quote
Old 01-23-2004, 06:39 PM   #6
Moonglobe
Better fan than rebelo!
 
Moonglobe's Avatar
 
Join Date: Apr 2003
Location: brain://localhost:left-side
Posts: 2,381
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.
__________________
there's no place i can be, since i found serenity.
Moonglobe is offline   Reply With Quote
Old 01-23-2004, 06:43 PM   #7
LordShryku
kung foo code monkey
 
LordShryku's Avatar
 
Join Date: Aug 2002
Location: Occupational Hypnotherapy
Posts: 7,473
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....
LordShryku is offline   Reply With Quote
Old 01-23-2004, 06:43 PM   #8
Moonglobe
Better fan than rebelo!
 
Moonglobe's Avatar
 
Join Date: Apr 2003
Location: brain://localhost:left-side
Posts: 2,381
Thanks Lord, i'll keep that in mind
__________________
there's no place i can be, since i found serenity.
Moonglobe is offline   Reply With Quote
Old 01-23-2004, 06:53 PM   #9
Moonglobe
Better fan than rebelo!
 
Moonglobe's Avatar
 
Join Date: Apr 2003
Location: brain://localhost:left-side
Posts: 2,381
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:"))
Attached Files
File Type: txt dbwrap.php.txt (14.3 KB, 76 views)
__________________
there's no place i can be, since i found serenity.
Moonglobe is offline   Reply With Quote
Old 01-25-2004, 03:32 AM   #10
Moonglobe
Better fan than rebelo!
 
Moonglobe's Avatar
 
Join Date: Apr 2003
Location: brain://localhost:left-side
Posts: 2,381
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).
Attached Files
File Type: txt dbwrap.php.txt (16.5 KB, 82 views)
__________________
there's no place i can be, since i found serenity.
Moonglobe is offline   Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT -4. The time now is 01:50 PM.






Acceptable Use Policy

internet.comMediabistrojusttechjobs.comGraphics.com

WebMediaBrands Corporate Info


Advertise | Newsletters | Feedback | Submit News

Legal Notices | Licensing | Permissions | Privacy Policy


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.