SQL连接使用预准备语句

时间:2016-05-08 09:57:48

标签: php

我有3个表求职者,认证和教育我想用预备语句查询。这是我的代码

$username= $_SESSION['username'];
$query = $pdo->prepare("SELECT jobseeker.username ,  jobseeker.first_name , jobseeker.last_name , education.university , certification.institution ,  from jobseeker inner join education on jobseeker.username=education.jobseeker_username inner join certification on jobseeker.username=certification.jobseeker_username where username=:username");
$query->bindParam(':username' , $username);
$query->execute();
$data = $query->fetchAll(PDO::FETCH_ASSOC);
return $data;

它不起作用。

2 个答案:

答案 0 :(得分:0)

您的查询出错,请在,之前删除使查询失败的逗号from jobseeker

SELECT jobseeker.username ,  jobseeker.first_name , jobseeker.last_name , education.university , certification.institution  from jobseeker inner join education on jobseeker.username=education.jobseeker_username inner join certification on jobseeker.username=certification.jobseeker_username where username=:username

答案 1 :(得分:0)

查询中的语法错误。
正确查询

SELECT jobseeker.username ,  jobseeker.first_name , jobseeker.last_name , education.university , certification.institution  
From jobseeker 
    INNER JOIN education 
      ON 
        jobseeker.username = education.jobseeker_username 
    INNER JOIN certification 
      ON 
        jobseeker.username = certification.jobseeker_username 
    where 
        jobseeker.username = :username