Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // database class
- <?php
- class Database {
- private $username;
- private $password;
- private $server;
- private $database;
- private $connection;
- public function __construct() {
- $this->username = 'weblog';
- $this->password = 'trololo';
- $this->server = 'localhost';
- $this->database = 'weblog_db';
- $this->Connect();
- mysql_close($this->connection);
- }
- private function Connect() {
- $this->connection = mysql_connect($this->server, $this->username, $this->password);
- if (!$this->connection) {
- die('Kon geen verbinding maken met de database.');
- }
- mysql_select_db('weblog_db');
- }
- private function Disconnect() {
- mysql_close($this->connection);
- }
- public function GetAllPages() {
- $this->Connect();
- $query = 'SELECT id, caption, created, lastedited FROM pages';
- $result = mysql_query($query);
- if (!$result) {
- die(mysql_error());
- } else {
- $tmpArray = array();
- while($row = mysql_fetch_assoc($result)){
- $tmpArray[] = $row;
- }
- }
- }
- }
- ?>
- // webpagina
- <?php
- session_start();
- require_once 'classes/database.php';
- if ($_SESSION['sessionid'] == '' || !isset($_SESSION['sessionid'])) {
- echo '<meta http-equiv="refresh" content="0;url=index.php">';
- } else {
- ?>
- <!DOCTYPE html>
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
- <title></title>
- </head>
- <body>
- <table>
- <tr>
- <td>ID</td>
- <td>Caption</td>
- </tr>
- <?php
- $database = new Database();
- $pages = $database->GetAllPages();
- print_r($pages);
- foreach ($pages as $page) {
- print_r($page);
- echo "<td>" . $page[1] . "</td>";
- //<td>" . $page['caption'] . "</td>";
- }
- ?>
- </table>
- </body>
- </html>
- <?php
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement