Advertisement
Guest User

Untitled

a guest
Jul 28th, 2015
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.90 KB | None | 0 0
  1. class Query{
  2.         private $queryError;
  3.  
  4.         public function __construct(){
  5.             $this->database = $GLOBALS['database'];
  6.         }
  7.  
  8.         public function preparedQuery($query, $array = array()){
  9.             try{
  10.                 $preparedQuery = $this->database->prepare($query);
  11.                 if($preparedQuery->execute($array)){
  12.                     return $preparedQuery;
  13.                 } else{
  14.                     return false;
  15.                 }
  16.             } catch(Exception $e){
  17.                 $this->queryError = $e;
  18.                 return false;
  19.             }
  20.         }
  21.  
  22.         public function rowQuery($query, $array){
  23.             try{
  24.                 $rowQuery = $this->database->prepare($query);
  25.                 if($rowQuery->execute($array)){
  26.                     $result = $rowQuery->fetchAll(PDO::FETCH_ASSOC);
  27.                     if(empty($result)){ // Needed to make sure false isnt returned for an empty array
  28.                         return array();
  29.                     } else{
  30.                         return $result;
  31.                     }
  32.                 }
  33.             } catch(Exception $e){
  34.                 $this->queryError = $e;
  35.                 return false;
  36.             }
  37.         }
  38.     }
  39.  
  40.     class Database{
  41.         public function __construct(){
  42.             $this->database = $GLOBALS['database'];
  43.         }
  44.         public function preparedQuery($query, $array = array()){
  45.             try{
  46.                 $preparedQuery = $this->database->prepare($query);
  47.                 if($preparedQuery->execute($array)){
  48.                     return $preparedQuery;
  49.                 } else{
  50.                     return false;
  51.                 }
  52.             } catch(Exception $e){
  53.                 Reply::error(["detail"=>"Something went horribly wrong. Please tell the sys admin to check the error log.".$e]);
  54.                 return false;
  55.             }
  56.         }
  57.         public function rowQuery($query, $array){
  58.             try{
  59.                 $rowQuery = $this->database->prepare($query);
  60.                 if($rowQuery->execute($array)){
  61.                     $result = $rowQuery->fetchAll(PDO::FETCH_ASSOC);
  62.                     if(empty($result)){ // Needed to make sure false isnt returned for an empty array
  63.                         return array();
  64.                     } else{
  65.                         return $result;
  66.                     }
  67.                 }
  68.             } catch(Exception $e){
  69.                 Reply::error(["detail"=>"Something went horribly wrong. Please tell the sys admin to check the error log.".$e]);
  70.                 return false;
  71.             }
  72.         }
  73.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement