Advertisement
Guest User

Untitled

a guest
Oct 5th, 2018
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.22 KB | None | 0 0
  1. // database class
  2.  
  3. <?php
  4.  
  5. class Database {
  6.  
  7.     private $username;
  8.     private $password;
  9.     private $server;
  10.     private $database;
  11.     private $connection;
  12.  
  13.     public function __construct() {
  14.         $this->username = 'weblog';
  15.         $this->password = 'trololo';
  16.         $this->server = 'localhost';
  17.         $this->database = 'weblog_db';
  18.        
  19.         $this->Connect();
  20.         mysql_close($this->connection);
  21.     }
  22.  
  23.     private function Connect() {
  24.         $this->connection = mysql_connect($this->server, $this->username, $this->password);
  25.        
  26.         if (!$this->connection) {
  27.             die('Kon geen verbinding maken met de database.');
  28.         }
  29.  
  30.         mysql_select_db('weblog_db');
  31.     }
  32.    
  33.     private function Disconnect() {
  34.         mysql_close($this->connection);
  35.     }
  36.  
  37.     public function GetAllPages() {
  38.         $this->Connect();
  39.         $query = 'SELECT id, caption, created, lastedited FROM pages';
  40.         $result = mysql_query($query);
  41.        
  42.         if (!$result) {
  43.             die(mysql_error());
  44.         } else {
  45.         $tmpArray = array();
  46.         while($row = mysql_fetch_assoc($result)){
  47.             $tmpArray[] = $row;
  48.         }
  49.         }
  50.     }
  51.  
  52. }
  53.  
  54. ?>
  55.  
  56.  
  57. // webpagina
  58.  
  59. <?php
  60. session_start();
  61.  
  62. require_once 'classes/database.php';
  63.  
  64. if ($_SESSION['sessionid'] == '' || !isset($_SESSION['sessionid'])) {
  65.     echo '<meta http-equiv="refresh" content="0;url=index.php">';
  66. } else {
  67.     ?>
  68.  
  69.     <!DOCTYPE html>
  70.     <html>
  71.         <head>
  72.             <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  73.             <title></title>
  74.         </head>
  75.         <body>
  76.             <table>
  77.                 <tr>
  78.                     <td>ID</td>
  79.                     <td>Caption</td>
  80.                 </tr>
  81.                 <?php
  82.                 $database = new Database();
  83.                 $pages = $database->GetAllPages();
  84.                 print_r($pages);
  85.                 foreach ($pages as $page) {
  86.                     print_r($page);
  87.                     echo "<td>" . $page[1] . "</td>";
  88.                           //<td>" . $page['caption'] . "</td>";
  89.                 }
  90.                 ?>
  91.             </table>
  92.         </body>
  93.     </html>
  94.     <?php
  95. }
  96. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement