Andrew Darby wrote:
Hello, all. I have a sort of theoretical/sort of dumb question about
PHP classes, which I haven't really worked with and don't entirely
understand the purpose of, so here goes:
Say i want to handle the add or update or delete of an item to a MySQL
db, and instead of having three functions (function addItem, function
updateItem, function deleteItem), it seems I could:
a) have one function (modifyItem) with some sort of attribute saying
which type it is, and then if/else through to the appropriate type of
operation based on this flag, i.e.,
modifyItem($array_of_data, 'update') chooses the update switch
b) have a modifyItem class, with the three possible functions inside
c) stick with my three original functions
Using any of these methods, how would you construct a query to actually
run? Do you need to pass in the fieldnames and the data? eg:
$data = array('newstitle' => $title, 'newscontent' => $data);
How about which table to place this data in?
It would get complicated I think..
I construct my queries elsewhere then hand it to my db class for
processing. It has some basic functions:
- Query (runs pg_query/mysql_query)
- Fetch (runs pg_fetch_assoc/mysql_fetch_assoc)
- Quote (runs pg_escape_string/mysql_escape_string)
and so on.
Is b) the sort of thing you might use a class for, or do I
misunderstand? If not, what would be some "classic" uses of classes
in our php/mysql world?
OOP is good for API's.
<shameless plug>
http://www.designmagick.com/article/18/PHP/Introduction-to-Object-Oriented-Programming
--
Postgresql & php tutorials
http://www.designmagick.com/
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php