Skip to content

Instantly share code, notes, and snippets.

@colshrapnel
Created May 19, 2020 05:13
Show Gist options
  • Save colshrapnel/48fc5e76d8bfb1cd74b0a8bc917ea355 to your computer and use it in GitHub Desktop.
Save colshrapnel/48fc5e76d8bfb1cd74b0a8bc917ea355 to your computer and use it in GitHub Desktop.
PDO wrapper review
  1. $db = null; is NOT the way to go.

  2. Get rid of all try catch operators. They just make mo sense. If you remove them, nothing would really change, because exceptions can report themselves, no assistance required, thank you

  3. Get git of all that global stuff. It's just gross. A class has its own means to persist the state. At least use a static variable to hold the connection. Better yet, do not use that static magic at all, create a regular instance with a constructor.

  4. Do not duplicate the code. All functions contain almost identical code. Reuse the functions, Luke!

     public static function query($sqlquery, $inserts = array()){
         $stmt = static::db->prepare($sqlquery);
         $stmt->execute($inserts);
         return $stmt;
     }
     public static function getDataRow($sqlquery, $inserts = array()){
         return static::query($sqlquery, $inserts)->fetch();
     }
     public static function getDataRows($sqlquery, $inserts = array()){
         return static::query($sqlquery, $inserts)->fetchAll();
     }
    
@OvO-Dev
Copy link

OvO-Dev commented May 19, 2020

Ah ok I unterstand. thx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment