Database table access class generator

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
pht
Forum Newbie
Posts: 7
Joined: Sat May 22, 2004 6:47 am

Database table access class generator

Post by pht »

I'm not sure if this is right place to ask comments for this php tool.

I've been developing some sort of code generator for php. Since my experience in pure programming area is only few years i decided to ask some comments and advices from you fellows, if it's ok? I have found very time consuming to make scripts and functions to access database and dozens of tables, insert, update, delete and get rows from there. So i made a little generator to do primary or may i say, initial work for me.

Generator builds up four files. Three of them are classes and one is a test file. Before generating files, user must know the name of the class, which he is going to produce. Most likely the name will be the same or at least have very close connection to the target table name. Second user must know all the columns in table and finally he must know the name of the target table, which is controlled by these classes. With these information code generator can build two of the three previously mentioned classes. Third class is a database connection class and it will need some connection and authentication information.

Two primary classes are 1) main class, that is an actual object presentation of the table and 2) database logic layer class for the main class. In real applications only the first one is used to access database table. Test file will show how the main class is used. It's very simple and effective, i think. Still a lot of work is left for the programmer because all class field data types will be a string type, as form (generator uses online form to get all needed informations) doesn't ask any data types for table columns.

I have placed code building tool to the website. There is a form, that can be submitted right away with default settings and see the results. For more deeper testing user can fill necessary fields and build up his own classes. The form is on:

http://mcenter.artesaani.net/OWAB/DbCla ... r/form.php

or documentation on:

http://mcenter.artesaani.net/OWAB/

where you must select PhpDbClassGenerator and it's sublinks. Documentation is on construction. I need some user experiences before publishing / contributing this tool more public. I would appreciate your comments. Thanks.
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

I've not (yet) looked at your class, but it sounds like you are writing a Data Access Object.
You might want to look at http://pear.php.net/package/DB_DataObject to get some ideas etc. PEAR's DataObject works well (regardless of if you like PEAR or not ;)) but of course, yours might be 'better' :o
pht
Forum Newbie
Posts: 7
Joined: Sat May 22, 2004 6:47 am

Post by pht »

It's quite like a DAO. But i think mine is more simple than PEAR's one, althought i have never heard that particular package. One amuzing coincidence happened, when i was reading SitePoint's php forum. One man had just posted same kind of ideas for the code generator. You may want to look funny cross posts at: http://www.sitepoint.com/forums/forumdisplay.php?f=147

Now i have to take o look at pear, what it does and how. Thanks for the link.
pht
Forum Newbie
Posts: 7
Joined: Sat May 22, 2004 6:47 am

Post by pht »

Ok, now checked PEAR DB_DataObject and it was fine. I got some ideas from there as you said. Have to be careful not to invent wheels again. :) Ok, if we are realistic, there is nothing new below the Sun.
Post Reply