0

I know the connection works as i have used this to insert data into the tables but i cant seem to pull it out. Any help would be greatly appreciated.

//Gets id from url
$projectid = $_GET['id'];
try{
    // DB CONNECTION
    $link = $database->connection;
    $link->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    // Query for projects
    $q = ("SELECT * FROM projects WHERE id=':pid'");
    $prep = $link->prepare($q);
    $array = array(
        ':pid' => $projectid
    );
    $prep->execute($array);
}catch(PDOException $pde){
    echo $pde->getMessage();
    die();
}
//Method to retrieve results
while ($r = $prep->fetch()) {
    echo $r['projectname'];
}
stephendev
  • 91
  • 1
  • 1
  • 9

1 Answers1

1

When you are using PDO with prepared statements, you don't need the single quotes around the pid term. PDO automatically inserts those for you. Just do:

$q = ("SELECT * FROM projects WHERE id = :pid");
larsAnders
  • 3,813
  • 1
  • 15
  • 19
  • Thank you :) I have been searching the internet for hours before i decided to post on here . – stephendev Apr 17 '14 at 20:56
  • 1
    No problem. Welcome to Stack Overflow. 4 minutes from now, you will be able to "accept" the answer by checking on the big checkmark next to it. If this solved your problem, I'd appreciate if you could do that. – larsAnders Apr 17 '14 at 20:59