Guest User

Untitled

a guest
Jan 27th, 2014
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.00 KB | None | 0 0
  1. <?php
  2. class dbManager {
  3.     // dbManager Alpha 0.0 - By: PrimoDeveloper
  4.     // 27/01/2014
  5.     // Public Domain
  6.    
  7.     public function readTable(string $table,array $whereVars=null) {
  8.         # Validação
  9.         if (!isset($table)) {return false;$cancel=true;} // Se a tabela não for indicada, cancelar.
  10.        
  11.         // Se a operação não foi cancelada
  12.         if (!$cancel==true) {
  13.             // Checa se usa WHERE ou não
  14.             if (!$whereVars==null && is_array($whereVars)) {$useWhere=true;} else {$useWhere=false;} // $useWhere, indica se vai usar o WHERE ou não
  15.             // TODO: Fazer o mesmo com outras variaveis
  16.        
  17.             # Query
  18.             $query = "SELECT FROM $table";
  19.             if ($useWhere==true) {
  20.                 $query.=" WHERE";
  21.                
  22.                 $count=count($whereVars);
  23.                 $i=-1;
  24.                 while($i<$count-1) {
  25.                     $i++;
  26.                     if ($i==$count) {
  27.                         $query.=" ".$whereVars[$i];
  28.                     }
  29.                     else {
  30.                         $query.=" ".$whereVars[$i]." AND";
  31.                     }
  32.                 }  
  33.             }
  34.         }
  35.        
  36.         // Fazer a conexão com BD e, PDO e outros akie
  37.         return true;// TODO: retornar o resultado
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment