Discover Habbo's history
Treat yourself with a Secret Santa gift.... of a random Wiki page for you to start exploring Habbo's history!
Happy holidays!
Celebrate with us at Habbox on the hotel, on our Forum and right here!
Join Habbox!
One of us! One of us! Click here to see the roles you could take as part of the Habbox community!


Page 1 of 2 12 LastLast
Results 1 to 10 of 11
  1. #1
    Join Date
    Jul 2004
    Location
    California
    Posts
    8,725
    Tokens
    3,789
    Habbo
    HotelUser

    Latest Awards:

    Default [PHP Coders] Criticize this! Lets compare!

    Hey there!

    It's not so much that I'm unhappy with this SQL class, or that it's dysfunctional (although if you have an improvement for it I'd love to hear about it), I'd just like to compare and contrast with with other user's coding techniques. I suppose I could have posted this on Stack Overflow but I would really like to see how other's code here who I could probably relate to more:



    If anyone else here has a similar setup, or, would like to code their interpretation of how they would code a class to complete a similar task, please do!
    I'm not crazy, ask my toaster.

  2. #2
    Join Date
    Sep 2009
    Location
    Hull
    Posts
    827
    Tokens
    0

    Latest Awards:

    Default

    Do you know what, I dont even go that far into PHP. I stick to basic that does the same job and is just a secure.

    The only time Id go that far into it is when I work for a company lol

    Lew.
    Im not here to be loved, I love to be hated :-}


  3. #3
    Join Date
    Nov 2008
    Location
    Cambridge, UK
    Posts
    901
    Tokens
    100

    Default

    Looks good, you've used " where you would be better off using ' in a few places though! Wouldn't a singleton design pattern be best for a database class, or is PHP to useless for that?
    we're smiling but we're close to tears, even after all these years

  4. #4
    Join Date
    Apr 2009
    Location
    United Kingdom
    Posts
    1,111
    Tokens
    100

    Latest Awards:

    Default

    I don't think I would personally have the two static functions as part of that class but I never do mysql classes solely because I only use mysql databases as a standard on my db class :\

    I like the code. Only think I don't link is some of the names you've given variables and obviously that's personal pref

  5. #5
    Join Date
    Aug 2009
    Posts
    78
    Tokens
    100

    Latest Awards:

    Default

    Did you consider using MySQLi or PDO? Half of them functions wouldn't be necessary if you did

  6. #6
    Join Date
    Mar 2008
    Posts
    5,108
    Tokens
    3,780

    Latest Awards:

    Default

    Here's a few things I would have done differently... I'm not sure what the g_count is... other then a connection count? Seems a bit pointless to a whole new instance of the class just for each database connection... but that's just me.

    I usually keep all mine referenced inside of one database class, and do something like this when setting it...

    PHP Code:
    <?php
    include "classes/database.class.php";

    $database_engine = new Database();

    // lets create a new connection //

    $database_connection $database_engine->create("localhost""blah username""password""database");

    // lets do a query... //

    $query $database_engine("SELECT * FROM `users` WHERE `username`='Caleb'"$database_connection);
    ?>
    Another thing... the debug on, debug off... could be simplified like this...

    PHP Code:
    function debug($status true)
    {
        if (
    $status) {
            
    $this->debug true;
        } else {
            
    $this->debug false;
        }

    Saves from having two functions... and can just pass it a bool and you're off to the races.

    Other then that, looks pretty good...

  7. #7
    Join Date
    Jul 2004
    Location
    California
    Posts
    8,725
    Tokens
    3,789
    Habbo
    HotelUser

    Latest Awards:

    Default

    Quote Originally Posted by Dentafrice View Post
    Here's a few things I would have done differently... I'm not sure what the g_count is... other then a connection count? Seems a bit pointless to a whole new instance of the class just for each database connection... but that's just me.

    I usually keep all mine referenced inside of one database class, and do something like this when setting it...

    PHP Code:
    <?php
    include "classes/database.class.php";

    $database_engine = new Database();

    // lets create a new connection //

    $database_connection $database_engine->create("localhost""blah username""password""database");

    // lets do a query... //

    $query $database_engine("SELECT * FROM `users` WHERE `username`='Caleb'"$database_connection);
    ?>
    Another thing... the debug on, debug off... could be simplified like this...

    PHP Code:
    function debug($status true)
    {
        if (
    $status) {
            
    $this->debug true;
        } else {
            
    $this->debug false;
        }

    Saves from having two functions... and can just pass it a bool and you're off to the races.

    Other then that, looks pretty good...
    I think you're right about the debug function, I should put it into one. I had to make g_count because if I had multiple instances of an sql object open at once before I called kill() it would error me because I was trying to open two connections to the database at once. I guess I could have connected to the database at the top of every script and then not had to worry about this but I suppose I wanted my functions to work more standalone which is why I wrote this sort of messy trick in
    I'm not crazy, ask my toaster.

  8. #8
    Join Date
    Mar 2008
    Posts
    5,108
    Tokens
    3,780

    Latest Awards:

    Default

    Hmm, gotcha. I just like to keep everything of mine inside the class, without relying on anything outside of it

  9. #9
    Join Date
    Jul 2004
    Location
    California
    Posts
    8,725
    Tokens
    3,789
    Habbo
    HotelUser

    Latest Awards:

    Default

    Fair enough. Global variables can get very hairy when they're abused
    I'm not crazy, ask my toaster.

  10. #10
    Join Date
    Nov 2008
    Location
    Cambridge, UK
    Posts
    901
    Tokens
    100

    Default

    Quote Originally Posted by HotelUser View Post
    I think you're right about the debug function, I should put it into one. I had to make g_count because if I had multiple instances of an sql object open at once before I called kill() it would error me because I was trying to open two connections to the database at once. I guess I could have connected to the database at the top of every script and then not had to worry about this but I suppose I wanted my functions to work more standalone which is why I wrote this sort of messy trick in
    Use Singleton.
    we're smiling but we're close to tears, even after all these years

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •