PDO:参数号无效:未定义参数

时间:2015-12-08 15:04:56

标签: php mysql select pdo

我在代码中找不到错误。我正在尝试在数组中获取结果。 SQL查询是正确的,我在我的PHPMYADMIN中尝试过。 $team是一个整理者。

我做错了什么?我是PDO的新手。

编辑:参数转储

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();

1 个答案:

答案 0 :(得分:0)

你没有告诉mysql什么是" employee_FK" ..所以正确的查询将是。你正在增加额外的" e"在"员工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();