SHARE
TWEET

Untitled

a guest Oct 17th, 2017 60 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function connect(){
  2.  
  3. $dbName = 'blog';
  4. $dbHost = 'localhost';
  5. $dbUser = 'root';
  6. $dbPass = '';
  7.  
  8.       $db = new PDO( "mysql:dbname=$dbName;host=$dbHost" , $dbUser , $dbPass );
  9.  
  10.       $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  11. }
  12.  
  13. function getPost($postSlug) {
  14.     connect();
  15. try {
  16.     $sql = $db->prepare("SELECT * FROM posts WHERE postSlug = ?");
  17.     $sql->bindParam(1, $postSlug);
  18.     $post = array();
  19.  
  20.     if ($sql->execute()) {
  21.         while ($post = $sql->fetch(PDO::FETCH_ASSOC)) {
  22.     ?>
  23.           <!-- Blog Article -->
  24.           <div class="card mb-4">
  25.             <img class="card-img-top" src="/blog/assets/images/<?php echo $post['postImage']; ?>" alt="Card image cap">
  26.             <div class="card-body">
  27.               <h2 class="card-title"><?php echo $post['postTitle']; ?></h2>
  28.               <p class="card-text"><?php echo $post['postContent']; ?></p>
  29.             </div>
  30.             <div class="card-footer text-muted">
  31.               Posted on <?php echo $post['postDate']; ?> by
  32.               <a href="#"><?php echo $post['postAuthorId']; ?></a>
  33.             </div>
  34.           </div>      
  35.     <?php
  36.         }
  37.     }      
  38.     } catch ( PDOException $e) {
  39.         echo $e->getMessage();
  40.         $sql = null;
  41.     }
  42. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top