Advertisement
Guest User

Untitled

a guest
Jul 16th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.47 KB | None | 0 0
  1. <?php
  2.  
  3. class pageHeader() {
  4.   private $data = null;
  5.   private $pdo = null;
  6.  
  7.   public function __construct(PDO $pdo) {
  8.     $this->pdo = $pdo;
  9.   }
  10.  
  11.   private function getData() {
  12.     if (is_null($this->data)) {
  13.       $statement = $PDO->prepare("SELECT * FROM head_info WHERE page_name = :page");
  14.       $statement->bindParam(':page', $page->createBinds(), PDO::PARAM_STR);
  15.       $statement->execute();
  16.        
  17.       $this->data = $statement->fetch();
  18.     }
  19.  
  20.     return $data;
  21.   }
  22.  
  23.   public function getDescription() {
  24.     return $this->getData('page_description');
  25.   }
  26.  
  27.   public function getTitle() {
  28.     return $this->getData('page_keywords');
  29.   }
  30.  
  31.   public function getKeywords() {
  32.     return $this->getData('page_title');
  33.   }
  34. }
  35.  
  36. $PDO = new PDO("mysql:host=localhost;dbname=oop", "root", "");
  37. $PDO->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
  38. $PDO->setAttribute(PDO::ATTR_ORACLE_NULLS, PDO::NULL_TO_STRING);
  39. $header = new pageHeader($PDO);
  40.  
  41.  
  42. // index.php ////////////////////////////////////////////////////////////////////
  43. <?php require_once 'classes.php'; ?>
  44.  
  45. <!DOCTYPE html>
  46. <html>
  47.     <head>
  48.         <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  49.         <meta name="description" content="<?php echo $header->getDescription(); ?>">
  50.         <meta name="keywords" content="<?php echo $header->getKeywords(); ?>">
  51.         <title><?php echo $header->getTitle(); ?></title>
  52.        
  53.     </head>
  54.     <body>
  55.     </body>
  56. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement