scotepi

PDO Function

May 10th, 2012
164
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. /*
  3. Usage:
  4. $pdoClass = PDO();
  5. $pdoStmt = PDO($statement);
  6. $pdoStmt = PDO($statement, $input_parameters);
  7.  
  8. */
  9.  
  10. function PDO($query=false, $data=false) {
  11.     global $pdo, $config;
  12.    
  13.     // Start PDO if its not started
  14.     if (!$pdo) {
  15.         $pdo = new PDO($config['pdo']['dsn'], $config['pdo']['username'], $config['pdo']['password'], $config['pdo']['driver_options']);
  16.     }
  17.    
  18.     // We want to run a query
  19.     if ($query) {
  20.        
  21.         // Data was passed so we want a prepare/execute
  22.         if (is_array($data)) {
  23.             $stmt = $pdo->prepare($query);
  24.             $stmt->execute($data);
  25.             return $stmt;
  26.        
  27.         // No data/invalid so just do query
  28.         } else {
  29.             return $pdo->query($query);
  30.         }
  31.    
  32.     // Just return the global $pdo
  33.     } else {
  34.         return $pdo;
  35.     }
  36. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×