3
I have the following problem. I have developed a PHP class for a site I am creating and in one of these functions I am having problems with PDO. In giving the command SELECT
I use the rowCount() function to check if you got results and the result is obviously 0 Rows. I already tested the QUERY and includes and is working normally.
Function code:
public function search($s) {
$db = $this->db;
$find = $db->prepare("SELECT `id`, `type`, `title`,`coverofpost`, `date` FROM `posts` WHERE title LIKE '% :tl %' OR tags LIKE '% :tags %' OR post LIKE '% :post %'");
$find->bindValue(":tl", $s, PDO::PARAM_STR);
$find->bindValue(":tags", $s, PDO::PARAM_STR);
$find->bindValue(":post", $s, PDO::PARAM_STR);
$find->execute();
if ($find->rowCount() > 0) {
$this->mountArray();
while ($data = $find->fetch(PDO::FETCH_ASSOC)) {
array_push($this->id, $data['id']);
array_push($this->type, $data['type']);
array_push($this->title, $data['title']);
array_push($this->cover, $data['coverofpost']);
array_push($this->time, $data['date']);
}
$this->makeUrls();
$this->makeArray();
$this->postArray['status'] = true;
} else {
$this->postArray['status'] = false;
}
return $this->postArray;
}
The return is always postArray['status'] //false
Remove the simple quotes from the query and pass the
%
in thebindValue()
– rray