Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Trad
- {
- public $id;
- public $count;
- }
- /**
- * Created by PhpStorm.
- * User: theophy
- * Date: 13/10/2017
- * Time: 5:38 AM
- */
- class Traditional1
- {
- private static $dbname = "playground";
- private static $username = "root";
- private static $password = "root";
- private $db;
- function __construct($id, $request)
- {
- $this->db = $this->connect();
- if ($request == "add")
- $this->like($id);
- else
- echo $this->getPost($id);
- echo "Done";
- }
- private function connect(){...}
- /**
- * @return PDO
- */
- private function getDb(){ .... return $this->db; }
- private function like($id)
- {
- $post = $this->getPost($id);
- $this->savePost($id, $post->count + 1);
- }
- /**
- * this is used to get a post
- * @param $id
- * @return Trad
- */
- private function getPost($id)
- {
- try {
- $stmt = $this->getDb()->prepare("select * from traditional1 where id='$id'");
- $stmt->setFetchMode(PDO::FETCH_CLASS, "Trad");
- $stmt->execute();
- return $stmt->fetch();
- } catch (PDOException $ex) {
- print $ex->getMessage();
- }
- }
- /**
- * this is used to perform a simple save of our post
- * @param $id
- * @param $total
- */
- private function savePost($id, $total)
- {
- //form sql
- $sql = "update traditional1 set count='$total' where id='$id'";
- $stmt = $this->getDb()->prepare($sql);
- $stmt->execute();
- }
- }
- new Traditional1($_GET['id'], $_GET['request']);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement