Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialac va
iOS Development Techdegree Student 5,061 Pointsproblem with prepare statement PDO
In function find, although I used prepare statement, when I click button "Recheck work", the app still announce an error: "make sure you use prepared statement". I truly don't understand how. Please help me
<?php
class sqlRepository extends PDO implements RepositoryInterface{
protected $db;
public function __construct($file){
try{
$this->db = new PDO("sqlite:" . __DIR__ . "/database.db");
$this->db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}catch (Exception $e){
echo "Unable to connect";
exit;
}
}
public function all($tableName){
try {
$results = $this->db->query("SELECT * FROM $tableName");
return $results->fetchAll(PDO::FETCH_OBJ);
} catch (Exception $e) {
echo "Unable to retrieved results";
exit;
}
}
public function find($entity, $value, $field = 'id'){
$statement = $this->db->preapre("SELECT * FROM :entity WHERE :field = :value");
$statement->bindParam(':entity', $entity, PDO::PARAM_STR);
$statement->bindParam(':field', $field, PDO::PARAM_STR);
$statement->bindParam(':value', $value, PDO::PARAM_STR);
$statement->execute();
return $statement->fetchAll(PDO::FETCH_OBJ);
}
}
1 Answer
ac va
iOS Development Techdegree Student 5,061 PointsSorry all, I found my problem: I typed wrong word "prepare". I also follow the question https://teamtreehouse.com/community/im-stumped-on-this-one to solve my problem Thanks all :)