|
-
Jun 16th, 2008, 04:19 PM
#2
Re: Some tips on my class?
All your vars can be changed by $db->var = 'value'; but it does not make sense to allow vars like the db user, pass etc to be changed after the object has been constructed. I suggest making any variable private unless you need to be able to change it in that way.
Another example, your result_set var only needs to be read doesn't it? So it would make sense to make that private and provide a function to read the var.
Even for vars that need to be set, its good to have the raw var private/protected and provide functions to read/write to this var, that way you can process the input when setting the var and check for bad data or peform some logging.
You could also provide access to the basic mysql functions like mysql_affected_rows(), mysql_fetch_array(), mysql_fetch_rows(), mysql_fetch_assoc().
You could make an update function that is similar to your insert, which will take a table name and an associative array as input - key as the field, value as the data, and perform a normal SQL UPDATE statement.
One more idea, you could have a switch so that the class automatically escapes all input by default, but can be turned off like $db->escape_input(false);
Edit: another nice feature would be a logging system of all the queries. So you could use a private var to keep a record of all the queries, then you would be able to provide information such as number of queries executed to render a page (as seen on some forums). It might also help when debugging and tracing deleted records. You could do anything you want with that data then, such as provide a function that exports the data in CSV format for example, or just directly output it to a flat file or database table.
PS: You arn't doing anything very wrong!
Last edited by the182guy; Jun 16th, 2008 at 04:55 PM.
Chris
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|