I can't find the error in my code. I'm trying to fetch the results in an array. The SQL query is correct, I tried it in my PHPMYADMIN. $team
is an interger.
What did I do wrong? I am very new to PDO.
EDIT: paramater dumps
SQL: [207] select a.start, a.end, a.type_FK, a.absences_ID, employee_FK, e.surname, e.name, e.cts from employee e JOIN absences a ON e.employee_ID=a.employee_FK WHERE approved = 0 and team_FK = :team order by start ASC Params: 1 Key: Name: [5] :team paramno=-1 name=[5] ":team" is_param=1 param_type=2
$sql = "select a.start, a.end, a.type_FK, a.absences_ID, employee_FK, e.surname, e.name, e.cts from employee e JOIN absences a ON e.employee_ID=a.employee_FK WHERE approved = 0 and team_FK = :team order by start ASC";
$stmt = $db->prepare($sql);
$stmt->execute(array(':team' => $team));
$unapproved = $stmt->fetchAll();
You are not telling mysql what is the table of "employee_FK" .. So the correct query will be . You were adding extra "e" near "employee e JOIN"
$sql = "select a.start, a.end, a.type_FK, a.absences_ID, a.employee_FK, e.surname, e.name, e.cts from employee JOIN absences a ON e.employee_ID=a.employee_FK WHERE approved = 0 and team_FK = :team order by start ASC";
$stmt = $db->prepare($sql);
$stmt->execute(array(':team' => $team));
$unapproved = $stmt->fetchAll();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.