PDO Database Abstraction Class

Miscellaneous code snippets and examples that members have posted

PDO Database Abstraction Class

Postby MattM » Fri Nov 09, 2007 6:28 am

I've been touching this up for 9 months now.

It has no known bugs, and I use it in several projects at work.

This works flawlessly with ODBC connections. I haven't tested it on anything else.

Implementation:
[PHP]//The Data Source Name, or DSN, contains the information required to connect to the database.
//replace foo:bar with your DSN
$db = new pdodb("foo:bar");[/PHP]
Attachments
pdodb.php.txt
Database Abstraction Layer Utilizing PDO
version: 0.9.4 10/02/07
(19.27 KiB) Downloaded 340 times
Last edited by MattM on Fri Nov 09, 2007 6:29 am, edited 1 time in total.
MattM
UA/UU Developer
UA/UU Developer
Gimpy Developer
Gimpy Developer
 
Posts: 886
Joined: Tue Jul 04, 2006 9:53 pm
Location: USA

Re: PDO Database Abstraction Class

Postby tuigii » Fri Nov 09, 2007 6:37 am

MattM wrote:Implementation:
[PHP]//The Data Source Name, or DSN, contains the information required to connect to the database.
//replace foo:bar with your DSN
$db = new pdodb("Excel");[/PHP]


That's what I'll try : running the roster on Excel - as one can approach it with DSN.
I'll post back with the result.....
User avatar
tuigii
WR.net Master
WR.net Master
 
Posts: 891
Joined: Wed Dec 27, 2006 12:57 pm
Location: Somewhere in the South Ouest of France

PDO Database Abstraction Class

Postby zanix » Fri Nov 09, 2007 6:43 am

Matt, you always come up with the most nifty things
Read the Forum Rules, the WiKi, and Search before posting!
WoWRoster v2.1 - SigGen v0.3.3.523 - WoWRosterDF
User avatar
zanix
Admin
Admin
WoWRoster.net Dev Team
WoWRoster.net Dev Team
UA/UU Developer
UA/UU Developer
 
Posts: 5546
Joined: Mon Jul 03, 2006 8:29 am
Location: Idaho Falls, Idaho
Realm: Doomhammer (PvE) - US

PDO Database Abstraction Class

Postby PleegWat » Fri Nov 09, 2007 8:42 pm

This may be a good idea for the new codebase. Along with other stuff, because I'm also thinking about a way to efficiently load a lot of data into data holder objects.
I <3 /bin/bash
User avatar
PleegWat
WoWRoster.net Dev Team
WoWRoster.net Dev Team
 
Posts: 1636
Joined: Tue Jul 04, 2006 1:43 pm

Re: PDO Database Abstraction Class

Postby MattM » Sat Nov 10, 2007 12:46 am

PleegWat wrote:This may be a good idea for the new codebase. Along with other stuff, because I'm also thinking about a way to efficiently load a lot of data into data holder objects.


What are data holder objects? I know of PHP Data Objects, and of BLOB fields, but
Last edited by MattM on Sat Nov 10, 2007 12:47 am, edited 1 time in total.
MattM
UA/UU Developer
UA/UU Developer
Gimpy Developer
Gimpy Developer
 
Posts: 886
Joined: Tue Jul 04, 2006 9:53 pm
Location: USA

Re: PDO Database Abstraction Class

Postby MattM » Sat Nov 10, 2007 12:48 am

tuigii wrote:
MattM wrote:Implementation:
[PHP]//The Data Source Name, or DSN, contains the information required to connect to the database.
//replace foo:bar with your DSN
$db = new pdodb("Excel");[/PHP]


That's what I'll try : running the roster on Excel - as one can approach it with DSN.
I'll post back with the result.....


it is Microsoft Jet for Access, I haven't heard of tapping into Excel before, I'm interested in your results.
MattM
UA/UU Developer
UA/UU Developer
Gimpy Developer
Gimpy Developer
 
Posts: 886
Joined: Tue Jul 04, 2006 9:53 pm
Location: USA

PDO Database Abstraction Class

Postby PleegWat » Sat Nov 10, 2007 3:45 am

The char/item/bag/skill/reputation classes in 1x are what I mean with data holder classes. They bundle the data with functions that use it. However, these classes should then also implement a generic interface that ties into the DB engine so it can load the data with only a couple of php statements, preferably with as few statements as possible.

Code: Select all

$guild 
= new roster_data_guild($guild_name$realm);
$guild->select();
$guild->members->select('%bank');
$guild->members->bags->select();
$guild->members->bank->select();
$guild->loadRecursive();

$items = new roster_data_items();
foreach( 
$guild->members as $member_id => $member )
{
    foreach( 
$member->bags as $item )
    {
        
$items->add($item);
    }
    foreach( 
$member->bank as $item )
    {
        
$items->add($item);
    }
}
 


Etcetera. Here roster_data_guild, roster_data_member, roster_data_item are objects containing (usually) a single item from a single table. roster_data_members, roster_data_items (bad name, needs improvement) would be a descendant implementing (at least) ArrayAccess, and would contain a list of single-row objects. The array itself would act a s a template for containing rows, so if the template is set to load bag and bank contents, then rows added later are also set to load those.
I <3 /bin/bash
User avatar
PleegWat
WoWRoster.net Dev Team
WoWRoster.net Dev Team
 
Posts: 1636
Joined: Tue Jul 04, 2006 1:43 pm

Re: PDO Database Abstraction Class

Postby tuigii » Sat Nov 10, 2007 4:37 am

MattM wrote:it is Microsoft Jet for Access, I haven't heard of tapping into Excel before, I'm interested in your results.

Just received from MSDN the Office 2007 'megapack' (it's longer then WoW to install : 4 DVD's - and it tries to change EVERY file on your disk) - but .... it 'could' work.

When activating addons, Excel comes to the foreground explain that it really doesn't like dynamic tables [where did we saw that before :wink: ]. "I should consider using MS SQL".

Nice to see that a recent Intel dual core really goes to 100 % for a couple of secondes when accesing the "data base".
Were talking real bloatware here....
User avatar
tuigii
WR.net Master
WR.net Master
 
Posts: 891
Joined: Wed Dec 27, 2006 12:57 pm
Location: Somewhere in the South Ouest of France

Re: PDO Database Abstraction Class

Postby MattM » Sat Nov 10, 2007 7:02 am

tuigii wrote:
MattM wrote:it is Microsoft Jet for Access, I haven't heard of tapping into Excel before, I'm interested in your results.

Just received from MSDN the Office 2007 'megapack' (it's longer then WoW to install : 4 DVD's - and it tries to change EVERY file on your disk) - but .... it 'could' work.

When activating addons, Excel comes to the foreground explain that it really doesn't like dynamic tables [where did we saw that before :wink: ]. "I should consider using MS SQL".

Nice to see that a recent Intel dual core really goes to 100 % for a couple of secondes when accesing the "data base".
Were talking real bloatware here....


lol Bloatware is microsofts middle uhh something.

I didn't know you can have "tables" in excel.
MattM
UA/UU Developer
UA/UU Developer
Gimpy Developer
Gimpy Developer
 
Posts: 886
Joined: Tue Jul 04, 2006 9:53 pm
Location: USA

Re: PDO Database Abstraction Class

Postby MattM » Sat Nov 10, 2007 7:08 am

zanix wrote:Matt, you always come up with the most nifty things
That means a lot to me :oops:
MattM
UA/UU Developer
UA/UU Developer
Gimpy Developer
Gimpy Developer
 
Posts: 886
Joined: Tue Jul 04, 2006 9:53 pm
Location: USA


Return to Code Cache

Who is online

Users browsing this forum: No registered users and 0 guests

cron