使用OOP和MySQL函数从数据库中检索数据?

时间:2015-04-02 22:49:01

标签: php oop mysqli

我正在构建一个小型Web工具来跟踪callcenter代理所发出的所有呼叫。我想知道,如何以有效的方式编写代码,以便以后可以非常轻松地完成更改。但由于我对OOP很陌生,我正在努力解决这些问题。我做错了什么?

 //DB Connection
class _GlobalFunctions {

  //Querys
  public function getfromDB($query_string) {
  global $mysqli;
  $mysqli->query("SET lc_time_names = 'de_DE'");
  if($query = $mysqli->query($query_string)) {
          return $query;        
          } else {
        return 0;
        }
  }
}

//Tasks
class _Tasks extends _GlobalFunctions {

    public $overdue = "";
    public $open = "";
    public $done = "";

    private function OverdueTasks() 
       {
          $query = getfromDB('SELECT * FROM tasks WHERE taskstst =0 AND  taskduedate < NOW() AND taskrspnsble ='.$_SESSION["user_id"]);           
          if ($query){
              $this->overdue = (int)$query;
              }  else {
                  $this->overdue = 'n/a';
                  } 


       }  

       public function OpenTasks() 
       {
           $query = 'SELECT * FROM tasks WHERE taskstst =0 AND  taskduedate > NOW() AND taskrspnsble ='.$_SESSION["user_id"];
            return $this->getfromDB($query);

       }   
}


//Output
$tasks = new _Tasks;                                    

if(!empty($tasks->overdue)) { 
    echo  $tasks->overdue;
};

0 个答案:

没有答案