php - How to: MySQLi to PDO -


i have code uses mysqli access database , want change pdo statement, can help? there's code:

function select_data($user_id, $start_date, $end_date) {     global $connection;      $sql = "select * attendancy         user_id = $user_id         , date >= '$start_date'         , date <= '$end_date'";      $result = $connection->query($sql);     if(!is_object($result)) return array();      $data = array();      while($row = $result->fetch_assoc())     {         $row['duration'] = count_work_hours($row);         $data[] = $row;     }      return $data; } 

function select_data($user_id, $start_date, $end_date) {     global $connection;      $sql = "select * attendancy         user_id = :user_id         , date >= :start_date         , date <= :end_date";      $stmt = $connection->prepare($sql,[pdo::attr_cursor => pdo::cursor_fwdonly]);      $stmt->execute([":user_id" => $user_id, ":start_date" => $start_date, ":end_date" => $end_date]);      $results = $stmt->fetchall(pdo::fetch_assoc);              if(!count($results)){         return array();     }     else{          $data = array();          foreach($results $row){              $row['duration'] = count_work_hours($row);             $data[] = $row;         }     }      return $data; } 

Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -