![]() |
Feedback on OOP Classes
Hello, I'm new to this forum, and I'm not exactly sure if this is the correct place to post this, but I hope it is.
Anyways, I've done 2 classes, a database class that handles the database querys and general stuff with the database, and a member class that manages the members in the database. And yea, I know that my comment lines are big. _database.php PHP Code:
_members.php PHP Code:
So I'm just wondering if you see any errors, or if you see anything that could be done better/safer. |
its nice keep up the good work.
ps: i will check if i see any bugs and report them to you :) |
Thanks :)
And btw, I know that the members system is really simple, but I will try to make a PM system for it later, and also maybe create a template class when I have the knowledge for it :) |
Aside from the enormous comments! I've never really been a big fan of the following code:
PHP Code:
I've always been a huge advocate of sprintf. You may enjoy reading the p if you haven't done so already. All in all though your code looks pretty clean to me. Easy to understand as well which is always a big plus! |
PHP Code:
And thanks for your comment :) About my comment blocks, I use PHPDesigner 2007, and when I use regular //commentlines, they go grey and I can barely see them. /**commentblock**/ is orange, which is alot easier to see. But you didn't see any php errors? :) EDIT: Actually to check the id is rather pointless, because it will always be an integer, however, the search for name would be more important to use this feature. PHP Code:
So it would look something like this: PHP Code:
|
I've got a whole bunch of things to comment on, so bear with me because it might turn out to be quite a long post! Note that the line numbers mentioned are taken from a direct copy/paste of the code in your first post.
Database Class
Member Class
Something I need to ask is, have you actually tried using your code on your own server (localhost?) at all? The first thing that I did was copy/paste your two classes into files and tried to execute them -- syntax errors show up right away (assuming you have error tracking/reporting turned on on your development machine). As for the grey comment lines in PHP Designer, can you not go into the settings and change the colour to something more readable (like the orange)? On the topic of comments, it's nice to see that you've at least thought about adding comments to your code but to be honest they're really not all that useful. For example, commenting the database constructor with "Our constructor that auto-loads" is just stating the blindly obvious. More useful would be to comment on what the constructor actually does "Defines global constants for the class to use and attempts to connect to the database." Most of the other comments follow in a similar vein; basically restating the associated function's name. P.S. Sorry for such a long post! |
I have not tried it, because my server on localhost can't use classes o_O
I have no idea why, but ohwell. I'll read the rest of the post, it's long as you said, but I'm glad someone had comments about my code! So thanks in advance, and I'll try to edit the things you mentioned :) |
Quote:
PHP Code:
About LIMIT 0,1... why? :S I gather the row where `u_id` = $u_id so I only get 1 row anyways.. |
Quote:
LIMIT 0, 1 in this case would not matter if the ID is a primary key that is set to unique. MySQL knows it's unique and it knows to find only 1. However, if you were acquiring the record via a non-unique index then LIMIT 0, 1 would prevent MySQL from trawling through your entire table looking for others that match your criteria. Therefore speeding up the query considerably. |
I see, well it's the primary key, dunno if it's unique however...
thanks for the heads up! |
MySQL knows that it's unique, but does a programmer glancing over the code?... ;)
|
Haha true :P
but anyways, got any ideas for the fetch function? |
PHP Code:
PHP Code:
|
Yea, I thought about that.. but I wasn't sure.. so if no arguements are given when calling the function(creating the object), it will give mysql error since the script cannot connect to db.
|
If no arguments are passed to the constructor, an error will be raised because the arguments are not optional.
At the moment if you don't want to pass along any host/user/password you have to create an instance of the object like new database('', '', ''). If you want to be able to write new database() with no arguments then you need to change the function to: |
Aha! :D
Damn I've tried to come up with this fetch function for like.. 40mins now, and I still can't figure out how to do it :S |
Syntax error:
PHP Code:
PHP Code:
|
Haha, thank you! :P
Such a lil >.< xD |
Quote:
PHP Code:
|
so if I were to do this:
PHP Code:
|
| All times are GMT. The time now is 01:54 PM. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0