Создал класс для подготовленных выражений. Посоветовали здесь
Такое сильно влияет на производительность?class FGLike {
public $con;
public $lc;
public $like_loc;
public $like_owner_id;
public $thread_id;
public $trgt_id;
public function __construct($loc) {
global $pdo_db;
$this->like_loc = $loc;
$this->like_owner_id = $owner;
$this->con = $pdo_db->prepare("SELECT * FROM likes WHERE like_location='$this->like_loc' AND target_id=':id' ORDER BY id ASC");
$this->con->bindParam(':id', $this->trgt_id);
$this->lc = $pdo_db->prepare("SELECT COUNT(*) FROM likes WHERE like_location='$this->like_loc' AND target_id=':id'");
$this->lc->bindParam(':id', $this->trgt_id);
}
public function getLikesList($trgt_id) {
$this->trgt_id = $trgt_id;
$this->lc->execute();
$count = $this->lc->fetch(PDO::FETCH_COLUMN);
if ($count > 0) {
$this->con->execute();
while ($likes = $this->con->fetch(PDO::FETCH_ASSOC)) {
$type = self::emi_like_type($likes[like_type]);
echo '<div class="like-pod '.$type.'"></div>';
}
} else {
echo 'null';
}
}
public function emi_like_type($lt = 1) {
switch ($lt) {
case 1:
$like_type = 'normal-like';
break;
case 2:
$like_type = 'haha-like';
break;
case 3:
$like_type = 'wow-like';
break;
case 4:
$like_type = 'love-like';
break;
case 5:
$like_type = 'sad-like';
break;
}
return $like_type;
}
}
Вызываю так
$c_likes = new FGLike(1);
$id = любое число из базы;
$c_likes->getLikesList($id);
Но выводит всегда null.
В чем ошибка?