SHARE
TWEET

Untitled

a guest Sep 26th, 2016 61 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.     class Database {
  3.  
  4.     private static $host = "localhost";
  5.     private static $db_name = "c9";
  6.     private static $username = "theandrewilliam";
  7.     private static $password = "";
  8.     private static $socket = "mysql";
  9.  
  10.     //Instance of class
  11.     private $instance = NULL;
  12.  
  13.     //Connection to Database (predefined function)
  14.     public function __construct(){
  15.  
  16.         if($this -> instance == NULL){
  17.             try{
  18.  
  19.                 $db = new PDO(self::$socket.':'.'host'.'='.self::$host.';'
  20.                 .'dbname'.'='.self::$db_name,self::$username,self::$password);
  21.  
  22.                 $this -> instance = $db;
  23.  
  24.             } catch(PDOException $e){
  25.  
  26.                 die($e -> getMessage());
  27.  
  28.             }
  29.         }
  30.  
  31.     }
  32.  
  33.     //Queries
  34.     public function query($sql){
  35.  
  36.         $query = $this -> instance = prepare($sql);
  37.         $query -> execute();
  38.  
  39.         return $query;
  40.  
  41.     }
  42.  
  43.     }
  44.    
  45. $data = new Database();
  46.  
  47. $sq = 'SELECT * FROM body';
  48.  
  49. $result = $data -> query($sq);
  50.  
  51. while($row = $result -> $query -> fetch(PDO::FETCH_ASSOC)){
  52.  
  53. $body = $row['text'];
  54. echo $body;
  55.  
  56. }
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
 
Top