Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Database {
- private static $host = "localhost";
- private static $db_name = "c9";
- private static $username = "theandrewilliam";
- private static $password = "";
- private static $socket = "mysql";
- //Instance of class
- private $instance = NULL;
- //Connection to Database (predefined function)
- public function __construct(){
- if($this -> instance == NULL){
- try{
- $db = new PDO(self::$socket.':'.'host'.'='.self::$host.';'
- .'dbname'.'='.self::$db_name,self::$username,self::$password);
- $this -> instance = $db;
- } catch(PDOException $e){
- die($e -> getMessage());
- }
- }
- }
- //Queries
- public function query($sql){
- $query = $this -> instance = prepare($sql);
- $query -> execute();
- return $query;
- }
- }
- $data = new Database();
- $sq = 'SELECT * FROM body';
- $result = $data -> query($sq);
- while($row = $result -> $query -> fetch(PDO::FETCH_ASSOC)){
- $body = $row['text'];
- echo $body;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement