Exemplo n.º 1
0
 /**
  * Inserts a ShortURL into the database.
  *
  * @param \ShortURL $url
  *            the ShortURL that needs be stored inside the database.
  * @return \\ShortURL which is updated by this method.
  */
 public function insertShortURL(\ShortURL $url)
 {
     $con = $this->getConnection();
     if (isset($con)) {
         $query = "INSERT INTO shortener (id, shortName, target, dateCreated, dateExpired) \n                VALUES (null, :shortName, :target, :dateCreated, :dateExpired)";
         $stmt = $con->prepare($query);
         $stmt->bindParam(':shortName', $url->getShortName());
         $stmt->bindParam(':target', $url->getTarget());
         $stmt->bindParam(':dateCreated', $url->getDateCreated());
         $stmt->bindParam(':dateExpired', $url->getDateExpire());
         $stmt->execute();
         $id = $con->lastInsertId();
         $url->setId($id);
         return $url;
     }
 }