You are here: Re: Abstracting SQL Statements In An Object « PHP Programming Language « IT news, forums, messages
Re: Abstracting SQL Statements In An Object

Posted by Jerry Stuckle on 07/30/05 17:49

richard wrote:
>
>>Seriously - it looks flexible, but overly complicated. I've found in
>>general the simpler the interface the better. Also, you're interface does
>>not abstract the sql at all.
>
>
> As far as database abstraction. You have to have a select or equeivelent,
> there has to be a where or equivelent, and there should be somekind of
> offset and of limit, and even or orderby. The only place I can see SQL
> snaek in is in the 'where's. But that would surely be easy to extend. You
> could even parse the sql out it only contains "field operation value" type
> stuff.
>

Yes, you need functions to retrieve data, add new data, change the data that is
there and remove old data. There should be some mechanism to sort the data and
possibly even limit the amount of data returned.

> Then the array is passed via the recordset to some database class that
> figures out what it needs to do, and provides that back to the recordset.
>
> The recordset can contain fields from >1 tables, and the sql is abstracted
> such that we cover field level securty, automated joins and outer joins.
> ther recordset can also contain other recordsets to cover the one to many
> relationship and even related recordsets covering the many to many
> relationship.
>
> $oRst= new Recordset('Rst',DATASOURCE);
> $oRst->SetDefinitionFromDatasource(array('Users'=>'','RoleMembers'=>''));
>
> where the following is approximately true:
> $gaDatasources[DATASOURCE]['Tables']['Users']=array(
> 'username'=>array('Type'=>'Text','Size'=>'30','Caption'=>'User
> Name','Validatation'=>array('NotBlank'),'PriKey'=>1,'StrToUpper'=>1),
> 'email'=>array('Type'=>'Text','Size'=>'200','Caption'=>'Email Address',
> 'Validation'=>array('NotBlank','EmailAddress','Unique'))
> );
>
> $gaDatasources[DATASOURCE]['Tables']['Role']=array(
> 'roleid' =>array('Type'=>'Text','Size'=>10,'Caption'=>'RoleID'),
> 'roledesc'=>array('Type'=>'Text','Size'=>200,'Caption'=>'RoleDesc'),
> );
>
> $gaDatasources[DATASOURCE]['Tables']['RoleMembers']=array(
> 'roleid' =>array('Type'=>'Reference','RefTable'=>'Role',
> 'RefField'=>'roleid', 'RefDisplayField'=>'roledesc'),
> 'username'=>array('Type'=>'Reference','RefTable'=>'Users',
> 'RefField'=>'username','RefDisplayField'=>'UserName'),
> );
>
> $oRst->ExecuteSQLArr(array('Command'=>'Select'));
>
>

Damn that looks needlessly complicated!

>>So I wrote a couple of classes (i.e. Object and ObjectList) which used a
>>flat file. Took me an hour or so and I have something which works
>
>
> OK, flat file stuff, that's easier.
>
I find it much harder than database stuff. You need to parse the file, ensuring
that the data is "clean". Searching and sorting must be done manually.
Inserting can be even more difficult. BTW - the same MySQL code took me about
20 minutes to write (it's not a huge table).

Give me a good database any day.

>
>>What happens if the column "username" changes, for
>>instance? A proper abstraction layer removes all dependencies from the
>>database.
>
>
> Well, you need to have some unique thing that represents the column
> username, why not use it's name?
>
>

Again - what if the database changes? For instance - what if someone decides it
should be "user"? Or what happens if they want it as "FirstName" and "LastName"?

>
>
>>Oh, and BTW - my company makes money writing PHP, also. I suspect most of
>>us here work are in the same boat.
>
>
> I thought most here have never programmed at all before and would quite like
> to make a cms.
>

I think most here HAVE programmed. There are more questions from the newbies -
but that's because they HAVE more questions.

Personally, I've been programming for almost 40 years. Started doing SQL
programming around 1983 and OO programming somewhere near 1988. Only been doing
PHP for five years or so.


--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация