From: Anacreo <an...@gm...> - 2007-10-04 05:43:02
|
Hmm that's a tricky one Walter... it depends on what the intention is of your class? Say I build a logging class, I'll generally throw in options such as "autodelete" (delete the physical log file on destruct), "echowrite" (write to stdout on log write), "htmllog" (store the log in a buffer as html), "bufferlog" (buffer the log)... anyhow I digress my point is if you want to write a nice class with handy dandy features that is re-useable (even by just you)... make them optionable. So I see value in writing your own wrapper DB class (I'd still incorporate the PDO library or similar into yours). So my options might be: datatypes_enforce datatypes_cache = &somesort of cookied variable (or possibly a path to a datafile if you'd rather have your class manage it in that way) so some pseudo code might be: ... $safedb = new safedb(); $safedb->datatypes_enforce = true; ... I would point out caching the data types as you will need to do a query before doing your select if you don't. So if I have some sort of server side cookie sessions going I may store some tables datatypes there, this can significantly speed up your site. In the past I've also used mapping tables with regex for a situation like this as well: $safedb->validate['tablename']['column'] = '/^[0-9+/()- ]*$/'; or $safedb->format['tablename']['column'] = 's/\s+//g'; The one bad/positive to this is that you might prefer to pass your data as an associative array instead of a SQL statement, ie: set $nugget['user'] = array( 'user' => $user, 'passwd' => "crypt(" . $pass . ")" ); $result = $safedb->write($nugget) Not sure if this was the kind of feedback you're looking for. On 10/3/07, jsWalter <jsW...@to...> wrote: > > > I'm rolling my own little DB class (pls, I don't need to hear about how > wonder this or that class is, thank you, I've reading over 2 dozen such > libaries) and I have a question to this group... > > Workflow: > 1) submit data form > 2) pull data from POST > 3) "clean" data > 4) update record > > Now, my question deals with step 3. > > On one hand, the cleansing of the data needs to be done by the developer. > > On the other, would it be logical for the DB class to take a whack at the > data set and to make sure each field is the data type that the database is > expecting? Or should the developer code that as well? > > Ideas? > > walter > > > > > ==================================================== > Taking it to the next level. > web.torres.ws/dev/php/walters_way > > > ------------------------------------------------------------------------- > This SF.net email is sponsored by: Splunk Inc. > Still grepping through log files to find problems? Stop. > Now Search log events and configuration files using AJAX and a browser. > Download your FREE copy of Splunk now >> http://get.splunk.com/ > _______________________________________________ > chiPHPug-discuss mailing list > chi...@li... > https://lists.sourceforge.net/lists/listinfo/chiphpug-discuss > |