prepare($query); $stmt->bindParam(":uid", $uid); $stmt->bindParam(":start", $start, PDO::PARAM_INT); $stmt->bindParam(":limit", $limit, PDO::PARAM_INT); // execute query $stmt->execute(); return $stmt; } static function readById($db, $uid, $id){ $query = self::select . " WHERE g.id = :id GROUP BY g.id ORDER BY created DESC "; // prepare query statement $stmt = $db->prepare($query); $stmt->bindParam(":id", $id); $stmt->bindParam(":uid", $uid); // execute query $stmt->execute(); return $stmt; } static function create($db, $item){ $query = "INSERT INTO " . self::table_name . " SET image_url=:imageUrl, image_thumb_url=:imageThumbUrl, description=:description, author=:author"; // prepare query $stmt = $db->prepare($query); // sanitize $imageUrl=htmlspecialchars(strip_tags($item['imageUrl'])); $imageThumbUrl=htmlspecialchars(strip_tags($item['imageThumbUrl'])); $description=htmlspecialchars(strip_tags($item['description'])); $author=htmlspecialchars(strip_tags($item['author'])); // bind values $stmt->bindParam(":imageUrl", $imageUrl); $stmt->bindParam(":imageThumbUrl", $imageThumbUrl); $stmt->bindParam(":description", $description); $stmt->bindParam(":author", $author); // execute query if($stmt->execute()){ return true; } return false; } static function fromRow($row) { return array( "id" => $row['id'], "imageUrl" => $row['image_url'], "imageThumbUrl" => $row['image_thumb_url'], "likes" => $row['likes'], "firstUserLiked" => User::createFromRow($row, 'lu'), "description" => $row['description'], "author" => User::createFromRow($row, 'au'), "created" => $row['created'], "currentUserLike" => Like::createFromRow($row, 'glcu'), ); } } ?>