Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace Post;
- class Repost
- {
- private $db;
- private $db_host = "localhost";
- private $db_name = "";
- private $db_user = "";
- private $db_pass = "";
- public function __construct()
- {
- $this->connectDb($this->db_name, $this->db_user, $this->db_pass, $this->db_host);
- }
- public function __destruct()
- {
- $this->db = null;
- }
- public function addPost($postinfo ,$url, $post) {
- $currentTime = new DateTime("now");
- $query = "INSERT INTO `reposts` (id, url, repost, date) VALUES (:id, :url, :repost, :date)";
- try {
- $this->db->beginTransaction();
- $result = $sth->execute(
- array(
- ':id' => $postinfo[0],
- ':url' => $url,
- ':repost' => $post,
- ':date' => $currentTime->getTimestamp(),
- )
- );
- $this->db->commit();
- } catch (\PDOException $e) {
- $this->db->rollback();
- echo "Database error: " . $e->getMessage();
- die();
- }
- if (!$result) {
- $info = $sth->errorInfo();
- printf("Database error %d %s", $info[1], $info[2]);
- die();
- }
- return $result;
- }
- public function post($url) {
- $wall = file_get_contents("https://api.vk.com/method/wall.repost?v=5.4&object=wall-" . $url . "&access_token=");
- $wall = json_decode($wall);
- $this = $wall->response;
- return $this;
- }
- public function connectdb($db_name, $db_user, $db_pass, $db_host = "localhost")
- {
- try {
- $this->db = new \pdo("mysql:host=$db_host;dbname=$db_name", $db_user, $db_pass);
- } catch (\pdoexception $e) {
- echo "database error: " . $e->getmessage();
- die();
- }
- $this->db->query('set names utf8');
- return $this;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement