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
Post a Comment